3 Replies Latest reply on Aug 11, 2008 3:12 AM by tony.herstell1

    Lazy Instatiation Exceptions...

    tony.herstell1

      <rich:dataTable id="users_list" value="#{userList}" var="eachUser"
      columnClasses="center" rows="20">

      ...

      <rich:column>
      <f:facet name="header">
      <h:outputText value="Avatar" />
      </f:facet>
      <h:outputText rendered="#{eachUser.avatar ne null}" value="has image" /> <!--value="#{XXeachUser.avatar.name}"-->
      <!--<s:graphicImage rendered="#{XXeachUser.avatar ne null}" fileName="#{XXeachUser.avatar.name}" value="#{XXeachUser.avatar.image}" />-->
      </rich:column>


      ....
      <rich:datascroller for="users_list" maxPages="10"/>




      The User is:
      @OneToOne(fetch = FetchType.LAZY, cascade={CascadeType.ALL})
      @JoinColumn(name = "avatar_id")
      public Image getAvatar()
      {
      return avatar;
      }

      public void setAvatar(Image avatar)
      {
      this.avatar = avatar;
      }


      and avatar is

      private String name;
      private String type;
      private byte[] image;



      Any ideas where to go from here would be useful.


        • 1. Re: Lazy Instatiation Exceptions...
          tony.herstell1

          I can now get the image up; but only the first time the page is displayed.

          If I click on "page 2" on the rich:datascroller I get lazy exception.

          I have fiddled and fiddled but really don't know why as SEAM promises NO lazy exceptions!

          this is the code that diplays the image:

          <s:graphicImage rendered="#{eachUser.avatar ne null}" value="#{eachUser.avatar.image}" />


          This is the code that manages the processing:
          /**
           * @author Tony Herstell
           * @version $Revision: 1.1 $ $Date: 2008-08-09 10:54:57 $
           */
          @SuppressWarnings("serial")
          @Stateful
          @Name("userListController")
          @Conversational
          public class UserListControllerImpl implements UserListController, Serializable {
          
           /**
           * Inject and leverage the Seam Logger.
           */
           @Logger
           private Log log;
          
           /**
           * Inject the EJB3 Persistence context in EXTENDED mode so will remain
           * "current" over multiple client/server round trips.
           */
           @PersistenceContext
           private EntityManager em;
          
           @DataModel
           private List<User> userList;
          
           @Factory("userList")
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           public void findUsers()
           {
           userList = em.createQuery("from User user order by user.surname asc").getResultList();
           }
          
           @TransactionAttribute(TransactionAttributeType.REQUIRED)
           @Begin
           public String enter() {
           return "userListController";
           }
          
           @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
           @End
           public String cancel() {
           log.info(">cancel");
           log.info("<cancel");
           return "home";
           }
          
           @Remove
           @Destroy
           @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
           public void destroy() {
           log.info("> destory");
           log.info("< destory");
           }
          
          }


          Here is my (possibly flawed" understanding:

          em keeps track of the "link with the database" and is handled by seam so that it is re-inserted each time it is required avoiding lazy exceptions.

          The factory gets called when userList is first used and populates it. As the bean is Conversational scope then it will only be created for a conversation and re-created for subsequent conversations (so re-reads from the Dbase for each conversation).

          TransactionAttributeType.REQUIRED is needed for the Factory; but doesnt seem to make a difference for any other methods (can't even remember why I do this - Was in Micheal Yuans book to reduce transation overhead I think!)

          Why is em not set back up by seam/RF when RF datascroller initiates a re-render of the next set of Users?

          • 2. Re: Lazy Instatiation Exceptions...
            tony.herstell1

            From reading this post (Seam)...

            http://www.seamframework.org/Community/EntityManagerInjectionJPAHibernateTomcat

            Is it possible that the em is not being re-injected properly as per his discussion.

            • 3. Re: Lazy Instatiation Exceptions...
              tony.herstell1

              Solved

              Didnt have (type=PersistenceContextType.EXTENDED)


              @PersistenceContext(type=PersistenceContextType.EXTENDED)