Regular |
|
Joined: Wed Jan 21, 2009 8:41 pm Posts: 54
|
I'm getting LazyInitializationExceptions but everything in our model is lazy="false"
so is there any idea why this is happening?
I have Sessions in ThreadLocals and I'm trying to ensure no operation is performed on the Session when the session is closed. We previously had Session per operation and I'm trying to make things behaviour as Session per Thread because of some performance issues with select-before-update as used with Session per operation. I don't see these exceptions with the older code that used Session per operation whereby every session operation was on it's own instance of a Session. When everything is eagerly loaded I wasn't expecting this exception.
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: COLLECTION NAME, no session or session was closed at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358) at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350) at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343) at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86) at org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:411) at java.util.HashMap.getEntry(HashMap.java:344) at java.util.HashMap.containsKey(HashMap.java:335) at java.util.HashSet.contains(HashSet.java:184) at org.apache.commons.lang.builder.ToStringStyle.isRegistered(ToStringStyle.java:168) at org.apache.commons.lang.builder.ToStringStyle.appendInternal(ToStringStyle.java:454) at org.apache.commons.lang.builder.ToStringStyle.append(ToStringStyle.java:428) at org.apache.commons.lang.builder.ToStringBuilder.append(ToStringBuilder.java:840)
Maven shows that I'm using
INFO] +- org.hibernate:hibernate:jar:3.2.2.ga:runtime (scope not updated to compile) [INFO] | \- org.hibernate:hibernate-entitymanager:jar:3.2.1.ga:compile [INFO] | +- org.hibernate:hibernate-annotations:jar:3.2.1.ga:compile
As I managed the Session in a ThreadLocal it generally works in that we are using a wrapper on top of hibernate and so therefore we ensure that a Session is created when appropriate and we try never to touch the Session when it's already closed. This assumes that we have complete control over what is happening but it seems that even with eager loading of all objects in the object model (historically this is how it's been because of session per operation) that in some cases like printing out the object it will still follow code paths that can trip LazyInitializationExceptions because eventually it wants to call hashCode on the collection.
|
|