Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate persist order

Tags:

hibernate

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?

like image 852
PaquitoSoft Avatar asked Nov 14 '22 11:11

PaquitoSoft


1 Answers

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).

like image 125
Manuel Darveau Avatar answered Feb 01 '23 16:02

Manuel Darveau