Announcement Announcement Module
No announcement yet.
Tiles and OpenSessionInViewInterceptor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles and OpenSessionInViewInterceptor

    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.initialize(
    	at net.sf.hibernate.collection.Set.iterator(
    	at test.web.section.common.taglib.MenuTag.renderTab(
    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"/>
    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?!


  • #2
    I guess the issue lies rather in the web.xml. Can you post it ?


    • #3
      Where you've wired the OpenSessionInViewInterceptor, try setting singleSession to false. This might do the trick, not sure... I'd also take a look at the API (which I'm sure you've already seen)... Here's a link to the API:


      • #4
        Matt, thanks, tried setting singleSession to false and read up and down thru both the interceptor and filter; no go. I decided to try just the filter for now.

        Seems this is set up correctly and like I said, when I remove the lazy="true" out of my hbm mapping, everything runs fine. It's only when it's true that stuff blows up. And when I restart the app, the first load works. After that everything blows up.

        I'm wondering this: In my DAO object that does my tab lookups and all my security checks (to see which user type can see which tabs), some methods call getHibernateTemplate() directly while others use the Session object directly. This is an artifact from earlier development and is being refactored and 'corrected'. However, I'm just wondering if the mix of those two would be affecting anything? I'm still using all the Spring calls to get and release the Session via my DAOs which extend HibernateDaoSupport - so no calling to Hibernate directly to get/release Sessions. Anyway, just a thought.

        Thanks again.