开发者

Hibernate persist order

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开发者_如何学Go 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜