3 Replies Latest reply on Sep 3, 2006 5:42 AM by raja05

    LIE and accessing collections in next request

    raja05

      I have a simple Seam app that displays the list of categories as a datatable and selecting a category from that. All works fine till that point. In the next request(i.e. after a category has been selected), Im trying to get the books that are associated with the category . The relation between Category to Books is OneToMany.
      When trying to access the books for that category, I get the following LIE

      Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.rajasaur.bookxchange.model.Category.books, 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.iterator(PersistentSet.java:138)
       at com.rajasaur.bookxchange.action.CategoryActionsBean.updateCategory(CategoryActionsBean.java:112)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
       at org.jboss.seam.interceptors.ValidationInterceptor.validateTargetComponent(ValidationInterceptor.java:64)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      


      CategoryActionsBean(Which is a Session Scoped Stateful bean) contains the following mappings.
      @In(create=true)
       private EntityManager em;
       @In(required=false) @Valid
       private Category category;
       @DataModel
       private List<Category> categories;
       @DataModelSelection(value="categories") @Out(required=false, scope=ScopeType.CONVERSATION)
       private Category selectedCategory;
      

      The Category Entity Bean also has 2 roles, category and selectedCategory, both of them in the Conversation Scope. Im totally at a loss as to why this is happening.
      According to the forums, if a component is in Conversational Scope and if we use the Seam managed PC, it should work , but I cant get this to work. If I put in a em.refresh before accessing the collection , then it works fine, but I thought Seam should be able to keep the collections intact from the previous request (as per Section 9.4 in the Seam Docs).

      If someone can point me to some docs or the problem, greatly appreciate it. Ive been debugging this for almost a few hours now, but cant get anywhere.

      Thanks
      Raja