'Hibernate setting referensing column to null

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 so the find failurs. Hibernate sets the value for that column to null.

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source