In pseudo I have a foo method that does as follows:
Code:
foo() {
Domain object = retrievalMethod();
}
Domain retrievalMethod() {
//begin transaction here
Domain object = session.get(Domain.class, 1);
//commit transaction here
}
My domain object contains some collections of other domain objects for which relationships are mapped in my hibernate mapping file.
When the transaction commits, dirty checking is performed as you would expect (remember nothing has actually been done apart from load retrieve a persistent object) so I would expect nothing to happen. However when I turn on hibernate logging I am getting a debug output saying a collection from my domain object has been dereferenced. Hibernate then proceeds to delete the objects with this query using an SQL statement. Then following this, hibernate then proceeds to re-add the very object that it has deleted using another SQL statement.
Could anybody shed some light on what could be causing this sort of behavior? I have trapsed through the actual hibernate source but to no avail. From what I can see in AbstractFlushingEventListener in the flushentities method hibernate iterates through every persistant object to perform dirty checking, schedule updates etc. In the case of my domain object it iterates through each of it's collections and marks them as reachable, but in the case of the actual entity which is a part of my collection, it is never setting the reachable flag to true (infact, I cannot even see a check to see if it is reachable when you are referencing a standalone object). So the flag is then set to false which triggers the delete update statement. This behaviour seems wrong to me, so I am guessing that I am missing something. Any help appreciated.