3 Replies Latest reply on Aug 11, 2008 3:12 AM by Tony Herstell

    Lazy Instatiation Exceptions...

    Tony Herstell Master

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


      <f:facet name="header">
      <h:outputText value="Avatar" />
      <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: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 Herstell Master

          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 $
          public class UserListControllerImpl implements UserListController, Serializable {
           * Inject and leverage the Seam Logger.
           private Log log;
           * Inject the EJB3 Persistence context in EXTENDED mode so will remain
           * "current" over multiple client/server round trips.
           private EntityManager em;
           private List<User> userList;
           public void findUsers()
           userList = em.createQuery("from User user order by user.surname asc").getResultList();
           public String enter() {
           return "userListController";
           public String cancel() {
           return "home";
           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 Herstell Master

            From reading this post (Seam)...


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

            • 3. Re: Lazy Instatiation Exceptions...
              Tony Herstell Master


              Didnt have (type=PersistenceContextType.EXTENDED)