wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Hibernate does not fill one-to-many after an insert and a select in the same transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate does not fill one-to-many after an insert and a select in the same transaction" Watch "Hibernate does not fill one-to-many after an insert and a select in the same transaction" New topic
Author

Hibernate does not fill one-to-many after an insert and a select in the same transaction

Tony David
Greenhorn

Joined: Mar 19, 2012
Posts: 15
Hi everyone,

I have a simple relationship case between 2 objects :
Process <- Operation



I try to insert an operation and then getting the process with all its operations, I do that in the same transaction.
It's not a good design because it involve dirty data, but it's useful for testing.

To do that :



I get all my process object in my returned list but the one-to-many for Operations is not filled (I don't get an exception but it's empty).
In logs I can see the request with the join between Process and operation but the Operation collection is not filled in Process.

I tried with HQL and criterias with exactly the same result.
If I commit the transaction after the insertion then call the select, it works, the operation collections is filled in Process entities.

I tried directly in the RDBMS with a transaction, with the same way an insert then call a select, new inserted lines are returned before the transaction rollback.

So I don't understand why Hibernate does not fill my operation collection, if someone
wan explain me this odd behavior, it would be helpful.
 
Don't get me started about those stupid light bulbs.
 
subject: Hibernate does not fill one-to-many after an insert and a select in the same transaction