I have a question about how Hibernate persists entity relations.
Let’s say I have an entity A that has a relation with entity B and another one with entity C.
I create an A instance and populate it with new instances of B and C. When I persist A I need C to be persisted previous to B. Is there any way of doing this?
I have a question about how Hibernate persists entity relations. Let’s say I have
Share
No, you can’t control the order.
The only thing you can do is call flush on the session after you made the A-C relation and then create the A-B relation. The flush will force hibernate to push new data to the database but will not commit the transaction.
After a flush, the data may or may not be visible to other transactions depending on the database configuration (on mysql for example, there are 4 transaction modes: http://dev.mysql.com/doc/refman/5.0/en/set-transaction.html).