8 Replies Latest reply on Apr 4, 2006 2:52 PM by Cory Virok

    Tomahawk dataScroller

    Cory Virok Newbie

      Has anyone had an issue using the Tomahawk dataScroller tag? I'm trying to use it with a regular h:dataTable and I am getting the annoying lazy initialization exception:

      org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed


      Here's the relevant stuff:

      @Name("Home")
      @Stateful
      @Scope(ScopeType.SESSION)
      ...
      public class HomeBean ... {
       @DataModel
       private List<User> userList;
      
       ...
      }
      


      <h:dataTable id="contactList" value="#{userList}" var="p">
       <f:facet name="header">
       <h:outputLink value="/invision/userSearch">
       <f:param name="isTherapist" value="false"/>
       Search
       </h:outputLink>
       </f:facet>
       <t:column>
       #{p.contacts.userName}
       </t:column>
      </h:dataTable>
      <t:dataScroller for="contactList"
       pageCountVar="pageCount"
       pageIndexVar="pageIndex"
       paginator="true">
      
       ...
      
      </t:dataScroller>
      


      Seems straightfoward enough... The problem comes when I click on the "next" page link for the dataScroller. At that point, the Lazy initialization exception is thrown due to #{p.contacts} being something crazy like:

      com.foo.bar.User$$EnhancerByCGLIB$$3e0be735

      Any ideas?

      Thanks,
      - Cory

        • 1. Re: Tomahawk dataScroller
          Mirko Adari Novice

          Have you put some data into that List?
          You have to point to list before you use it. It means you have to initialize it.
          Call contacts.size(); before using it.
          And that is not crazy way of viewing. It`s how seam see`s it and is not ment to be for youi.

          • 2. Re: Tomahawk dataScroller
            Gavin King Master

            Either init the collection eagerly, or use a Seam-managed persistence context.

            • 3. Re: Tomahawk dataScroller
              Cory Virok Newbie

              Thanks for your reply. I've dealt with the lazy initialization problem before and have done things like "list.size()" to force eager loading. The *correct* solution always seems to be a tweak in the Seam scoping annotations for either the bean or the list I want to outject.

              Yes, there is some data in the list and it displays correctly when the page is initially loaded. The problem comes when I use the data scroller to go to the next "page" of data by clicking on the ">" or "next" links.

              - Cory

              • 4. Re: Tomahawk dataScroller
                Cory Virok Newbie

                Thanks for your reply Gavin.

                I am using Seam's extended persistence manager:

                <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>


                - Cory

                • 5. Re: Tomahawk dataScroller
                  Gavin King Master

                  So, as long as you are within the scope of a conversation, and do not serialize the objects, you will never recieve a LazyInitializationException.

                  Are you sure you are actually using the seam-managed PC in your code (you are not using @PersistenceContext, right?)....

                  • 6. Re: Tomahawk dataScroller
                    Cory Virok Newbie

                    Correct,

                    All of my entityManager code uses the Seam @In annotation.

                    • 7. Re: Tomahawk dataScroller
                      Cory Virok Newbie

                      The only thing I can think is happening is that the dataScroller object is using the fully loaded element inside the DataModel, (which is fine and correct) but inside the dataTable, is is using a member of the current DataModel element which is *not* fully loaded and is doing this outside of the Conversation. (btw my bean is Session, not Conversation scoped.)

                      Does anyone know or have any examples of using dataScroller with a dataTable that uses a Seam @DataModel that I could see?

                      Thanks,
                      - Cory

                      • 8. Re: Tomahawk dataScroller
                        Cory Virok Newbie

                        The short term work-around is to force loading in a loop for the DataModel's @Factory method, (doing a bunch of System.out() on PKs of elements displayed in the dataTable.) This tells me that the request by the dataScroller is outside of the Conversation scope, (does it cache the DataModel on first load?) or my scoping is getting hosed somewhere.

                        - Cory