I found a strange behavior in Hibernate, that I can't explain.
I have a folowing scenarion
Code:
session.update(parent);
//add new child to the parent object
Child c = new Child()
....
parent.addChild(c);
...
session.clear(); // session is cleared or closed and another session opened
session.update(parent);
session.evict(parent); // at this moment the session should be empty?
session.flush(); // throws an exception. why ??????
=> org.hibernate.AssertionFailure: possible nonthreadsafe access to session
It seems like as the child objects are not evicted properly or something like that,
but if I debug, I can see that
session.getStatistics().getCollectionCount() == 0
and
session.getStatistics().getEntityCount() == 0
before flush.
And this code works
Code:
session.update(parent);
//add new child to the parent object
Child c = new Child()
....
parent.addChild(c);
...
session.clear(); // session is cleared or closed and another session opened
session.update(parent);
//close or clear session and update one more time
session.clear(); // session is cleared or closed and another session opened
session.update(parent);
session.evict(parent); // at this moment the session should be empty?
session.flush(); // no exception is thrown. why??????
Can somebody explain this behavior?