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?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With