-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationExceptions even when things are non lazy?
PostPosted: Mon Dec 28, 2009 8:08 pm 
Regular
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.