2 Replies Latest reply on Aug 24, 2010 9:28 PM by Michal Petrik

    Seam managed persistence context used in page scope bean + LIE

    Michal Petrik Newbie

      hope that someone can help me with this.

      I would like to try the feature of Seam managed persistence context (as I understand from documentation) that it can be spanned across multiple request without need to reload data from db to synchronize them with context. But I can't get work even this simple scenario and always get the LazyEvaluationException. Probably I'm missing something crucial but I don't know what.

      This is the page scoped bean:

      public class UserManagementBean implements Serializable{
           private static final long serialVersionUID = -20674003247424563L;
           EntityManager entityManager;
           List<User> usersList;
           User selectedUser;
           private User detailedUser;
           private boolean detailRendered = false;
           public void initUsers(){
                usersList = entityManager.createNamedQuery("getUsers").getResultList();
           public void showDetail(){
                detailedUser = selectedUser;
                detailRendered = true;
              public boolean isDetailRendered() {
                return detailRendered;
              public User getDetailedUser() {
                return detailedUser;

      And this is the .xhtml page:

      I just want to show some details of User entity in the ajax rendered output panel when the link in data table is clicked. But the problem is that the User entity has lazy initialized collection of roles that I also want to display in that panel. And it leads to LIE.

      I thought if I use seam managed persistence context that once the entity is loaded it remains managed until the entity manger is detached at the end of the bean scope.

      <rich:panel id="cn" header="#{messages.users}">
                     <a4j:outputPanel id="udp" rendered="#{userManagement.detailRendered}">
                               value="#{userManagement.detailedUser.commonName}" /></p>
                          <p><h:outputText value="#{userManagement.detailedUser.email}" /></p>
                          <br />
                          <br />
                          <h:outputText value="#{messages.memberOf}" />
                          <rich:separator id="sp1" />
                          <h:dataTable id="rol"
                               value="#{userManagement.detailedUser.rolesSorted}" var="role">
                                    <s:link id="pl" view="/#{links.roleProfile}" propagation="none"
                                         <f:param name="roleName" value="#{role.name}" />
                     <h:form id="tfrm">
                          <rich:dataTable id="us" var="user" value="#{usersList}" rows="15">
                               <f:facet name="header" id="fh">
                                    <rich:columnGroup id="cg">
                                              <h:outputText value="#{messages.username}" />
                                         <rich:column id="hn">
                                              <h:outputText value="#{messages.name}" />
                                         <rich:column id="hp" />
                               <rich:column id="u">
                                    <h:outputText value="#{user.username}" />
                               <rich:column id="n">
                                    <h:outputText value="#{user.commonName}" />
                               <rich:column id="p">
                                    <a4j:commandLink id="lpr" ajaxSingle="true"
                                         title="#{messages.details}" reRender="cn"
                                         <h:graphicImage id="pi" value="#{images.details}" />
                          <rich:datascroller id="usscr" renderIfSinglePage="false"
                               maxPages="10" for="us" />

      Thanks for reply.