I am migrating to a new empty database. When I try to persist an entity in the new database where one column in the new entity has a foregnkey to another table in a M:1 relation Hibernate tries to find that entity but it is not there yet so the find fails. Hibernate sets the value for that column to null instead of leaving the value used for the find.
If I create the referenced row Hibernate sets the value of the column correctly.
Is there a way to get around the problem that a non-existing entity in a M:1 relation forces Hibernate to set that kolumn to null instead of the correct value?
Using Payara 5.24, Hibernate 5.4.21 and Java 8 build 172
The column is set to null because the association is set to an unmanaged entity. You have to make this entity managed first by using a proper
CascadeType configuration on the association mapping or by persisting the entity before the other.
This is the annotations for the attribute:
@Column(name=serviceid, insertable=false, updatable=false)
public Long getServiceID()|
It is a very large database with over 400 tables and lots of constraints that makes it impossible to merge the data in the “right” order. The idea is to merge the database and after the data is in the databse applu all referensial constraints.
Hibernate tries to find that entity but it is not there yet so the find fails.
The mapping you posted does not make sense with this sentence. Hibernate doesn’t do random checks. So if you need better help, you have to provide some error details. What exceptions do you see?
It is a very large database with over 400 tables and lots of constraints that makes it impossible to merge the data in the “right” order.
It’s always a large database , but if you need help, you need to provide us details. How are you trying to persist data? Show some code snippets.