jlee
Nov 15th, 2005, 12:49 PM
Getting a LazyInitializationException on my pages:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize
a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.i nitialize(PersistentCollection.java:209)
at net.sf.hibernate.collection.PersistentCollection.r ead(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java: 130)
at test.web.section.common.taglib.MenuTag.renderTab(M enuTag.java:181)
I'm using Spring 1.2.5, Hibernate 2.1.7, and whatever the latest Tiles version is. I'm trying to speed up things on my site, especially rendering of my navigation tabs at the top of the page and so I figured I'd set up lazy init in my Hibernate objects, which makes sense.
I've declared the OSIVInterceptor and when I first hit my site after restarting the server, everything looks fine (some log output):
[11/15/05-09:36 DEBUG OpenSessionInViewInterceptor.preHandle] Opening single Hibernate Session in OpenSessionInViewInterceptor
[11/15/05-09:36 DEBUG SessionFactoryUtils.getSession] Opening Hibernate Session
[11/15/05-09:36 DEBUG SecureInterceptor.preHandle] entered
.....
[11/15/05-09:36 DEBUG InternalResourceView.renderMergedOutputModel] Forwarded to resource [publicListPage] in InternalResourceView 'publicListPage'
[11/15/05-09:36 DEBUG OpenSessionInViewInterceptor.afterCompletion] Closing single Hibernate Session in OpenSessionInViewInterceptor
[11/15/05-09:36 DEBUG SessionFactoryUtils.doClose] Closing Hibernate Session
So I can see the single session is working correctly and like I said, the page renders the first time fine. However, when I go to another tab/page, I get the above lazy init error. Not sure what's going on. Here's the relevant info of my tab hbm xml that specifies any lazy behavior:
<!-- parent-child relationship -->
<set name="children" order-by="tab_order" lazy="true">
<key column="parent"/>
<one-to-many class="test.web.persist.hibernate.system.TabNav"/>
</set>
If I don't use the lazy parent/child relationship, my tabs always render fine, however, they take longer (by longer I mean 300 or 400 .ms). So I'm not sure if my problem is in the mapping or in the interceptor.
Any clues, ideas, suggestions?!
Thanks
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize
a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.i nitialize(PersistentCollection.java:209)
at net.sf.hibernate.collection.PersistentCollection.r ead(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java: 130)
at test.web.section.common.taglib.MenuTag.renderTab(M enuTag.java:181)
I'm using Spring 1.2.5, Hibernate 2.1.7, and whatever the latest Tiles version is. I'm trying to speed up things on my site, especially rendering of my navigation tabs at the top of the page and so I figured I'd set up lazy init in my Hibernate objects, which makes sense.
I've declared the OSIVInterceptor and when I first hit my site after restarting the server, everything looks fine (some log output):
[11/15/05-09:36 DEBUG OpenSessionInViewInterceptor.preHandle] Opening single Hibernate Session in OpenSessionInViewInterceptor
[11/15/05-09:36 DEBUG SessionFactoryUtils.getSession] Opening Hibernate Session
[11/15/05-09:36 DEBUG SecureInterceptor.preHandle] entered
.....
[11/15/05-09:36 DEBUG InternalResourceView.renderMergedOutputModel] Forwarded to resource [publicListPage] in InternalResourceView 'publicListPage'
[11/15/05-09:36 DEBUG OpenSessionInViewInterceptor.afterCompletion] Closing single Hibernate Session in OpenSessionInViewInterceptor
[11/15/05-09:36 DEBUG SessionFactoryUtils.doClose] Closing Hibernate Session
So I can see the single session is working correctly and like I said, the page renders the first time fine. However, when I go to another tab/page, I get the above lazy init error. Not sure what's going on. Here's the relevant info of my tab hbm xml that specifies any lazy behavior:
<!-- parent-child relationship -->
<set name="children" order-by="tab_order" lazy="true">
<key column="parent"/>
<one-to-many class="test.web.persist.hibernate.system.TabNav"/>
</set>
If I don't use the lazy parent/child relationship, my tabs always render fine, however, they take longer (by longer I mean 300 or 400 .ms). So I'm not sure if my problem is in the mapping or in the interceptor.
Any clues, ideas, suggestions?!
Thanks