10 Replies Latest reply on May 21, 2006 2:12 PM by elgamal

    Set iteration error: org.hibernate.collection.PersistentSet,

    kryptontri

      Hi, I;m trying to iterate through a set of data
      but when i try to retrieve values it fails with

      21:51:09,278 ERROR [STDERR] 21-Mar-2006 21:51:09 com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View
      javax.el.ELException: /viewGalleryPage.xhtml: Bean: org.hibernate.collection.PersistentSet, property: 0
       at com.sun.facelets.compiler.UIText.encodeBegin(UIText.java:51)
       at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:511)
       at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:518)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:447)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:92)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BasePro
      tocol.java:663)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      21:51:09,288 ERROR [STDERR] 21-Mar-2006 21:51:09 com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Took Type: java.io.PrintWriter
      


      This is my view
       <!-- Images -->
       <c:choose>
       <c:when test='${galleryPage.images == null}'>
       Empty Gallery
       </c:when>
       <c:otherwise>
       <c:forEach var="image" items="${galleryPage.images}">
       Image Id is ${image}.id
       </c:forEach>
       </c:otherwise>
       </c:choose>
       <!-- End Images -->
      


      And my backing bean

      @Entity
      @Name("galleryPage")
      @Scope(SESSION)
      @Inheritance(strategy = InheritanceType.JOINED)
      public class GalleryPage extends Page {
      
       private String description = null;
       private Set<Image> images = new HashSet<Image>(0);
      
       @NotNull
       @Length (min = 5, max = 500, message = "Description is required and must be at most {max} characters long.")
       public String getDescription() {
       return description;
       }
      
       public void setDescription(String description) {
       this.description = description;
       }
      
       @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER, mappedBy="galleryPage")
       public Set<Image> getImages() {
       return images;
       }
      
       public void setImages(Set<Image> images) {
       this.images = images;
       }
      
       public void addImage(Image image) {
       this.images.add(image);
       }
      
       public void removeImage(Image image) {
       this.images.remove(image);
       }
      


      Any ideas people? TIA

        • 1. Re: Set iteration error: org.hibernate.collection.Persistent
          kryptontri

          Ack, sorry cut and paste type for my view, it is actually

           Image Id is ${image.id}
          

          but the error is still occurring? ..erm .. help



          • 2. Re: Set iteration error: org.hibernate.collection.Persistent
            kryptontri

            I've used <h:dataTable> and the exception has gone, but
            unfortunately, no images are returned. Looking further ..

            • 3. Re: Set iteration error: org.hibernate.collection.Persistent
              gavin.king

              It is usually dodgy to try and use JSTL tags like c:forEach in JSF. They just don't work very well.

              • 4. Re: Set iteration error: org.hibernate.collection.Persistent
                superfis

                 

                "gavin.king@jboss.com" wrote:
                It is usually dodgy to try and use JSTL tags like c:forEach in JSF. They just don't work very well.


                What is suggested to be used insted of JSTL tags? How to solve problem like mine, which looks like this:

                In my SFSB there is representation of chairs in cinema and each Seat instance has row and number values:
                ...
                @DataModel
                List<List> allSeats;
                ...

                and I would like to put seats in 2 dimensions on MyFaces site. Mostly natural for me is to use c:forEach in c:forEach and navigate in 2 dims but this tag doesn't work correctly with JSF.

                What's the correct way to do that?

                Regards, Slawek

                • 5. Re: Set iteration error: org.hibernate.collection.Persistent
                  gavin.king

                  You should use a h:dataTable or some custom JSF control, or, if you are using facelets, try using ui:repeat.

                  • 6. Re: Set iteration error: org.hibernate.collection.Persistent
                    superfis

                     

                    "gavin.king@jboss.com" wrote:
                    You should use a h:dataTable or some custom JSF control, or, if you are using facelets, try using ui:repeat.


                    I've used ui:repeat with code:

                    <table>
                     <ui:repeat value="#{allSeats}" var="row">
                     <tr>
                     <ui:repeat value="#{row}" var="seat">
                     <td><span class="seat" id="#{seat.place}">#{seat.number}</span></td>
                    
                     </ui:repeat>
                     </tr>
                     </ui:repeat>
                     </table>
                    

                    but it doesn't work I expected. Result looks like that:

                    <table>
                     <tr>
                     <td><span class="seat" id="1,1">1</span></td>
                     </tr>
                     <tr>
                     <td><span class="seat" id="1,2">2</span></td>
                     </tr>
                     ...
                     </table>


                    Why doesn't it work as loop in loop ( tag repeats too often)? I've exchanged WEB-INF\lib\jsf-facelets.jar file with existed in Seam examples to have newest one and I'm not sure it's enough.

                    How to overcome it?

                    cheers,
                    Slawek


                    • 7. Re: Set iteration error: org.hibernate.collection.Persistent
                      elgamal

                      Hi,

                      I tried to do exactly the same with <c:forEach> and then I came across this post and tried using <ui:repeat>, but I am receiving the same error even when using the <ui:repeat> tag.

                      Here is the error stack:

                      SCHWERWIEGEND: Error Rendering View[/user/detailsView.xhtml]
                      javax.el.ELException: /user/detailsView.xhtml: Bean: org.hibernate.collection.PersistentSet, property: application
                       at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
                       at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
                       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:232)
                       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
                       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:554)
                       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
                       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
                       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                       at java.lang.Thread.run(Thread.java:595)
                      00:52:49,750 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
                      javax.el.ELException: /user/detailsView.xhtml: Bean: org.hibernate.collection.PersistentSet, property: application
                       at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
                       at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
                       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:232)
                       at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
                       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:554)
                       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:352)
                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
                       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
                       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                       at java.lang.Thread.run(Thread.java:595)


                      The code for the my .xhtml:
                      <ui:repeat value="#{currentUser.applications}" var="app">
                       <tr>
                       <td>#{app.application}</td>
                       </tr>
                      </ui:repeat>


                      currentUser is of type Userand is being held in the session.

                      The User Class:
                      @Entity
                      @Name("user")
                      public class User implements Serializable
                      {
                       private Long id;
                       [...]
                       private Set<Application> applications = new HashSet<Application>();
                       [...]
                       @ManyToMany(fetch=FetchType.EAGER)
                       @JoinTable(name="user_application")
                       public Set<Application> getApplications()
                       {
                       return applications;
                       }
                      
                       public void setApplications(Set<Application> applications)
                       {
                       this.applications= applications;
                       }


                      The Application Class:
                      @Entity
                      @Name("application")
                      public class Application implements Serializable
                      {
                       private Integer id;
                       private String application;
                      
                       @Id
                       @GeneratedValue(strategy=GenerationType.IDENTITY)
                       public Integer getId()
                       {
                       return id;
                       }
                      
                       public void setId(Integer id)
                       {
                       this.id = id;
                       }
                      
                       @NotNull
                       public String getApplication()
                       {
                       return application;
                       }
                      
                       public void setApplication(String application)
                       {
                       this.application= application;
                       }
                      }


                      • 8. Re: Set iteration error: org.hibernate.collection.Persistent
                        elgamal

                        I went to bed, woke up, started AS and it worked :-)

                        Hehe, seriously I think upgrading to myfaces 1.1.3 solved the problem. Looks like the bug has already been fixed in 1.1.2 (so i guess i was still using 1.1.1 *G*) as I found in the release notes for 1.1.2.

                        [MYFACES-733] - javax.faces.el.PropertyNotFoundException: Bean:
                        org.hibernate.collection.PersistentSet, property: id


                        Greets....

                        • 9. Re: Set iteration error: org.hibernate.collection.Persistent
                          elgamal

                          Ok, that was not the solution actually. I forgot, that i changed from Set to List. It seems like <ui:repeat> can't handle Set's.

                          But now with List I have other problems, e.g:

                          org.hibernate.HibernateException: cannot simultaneously fetch multiple bags


                          But there are enough other posts in this forum and in the hibernate forum about this exception. I'm still searching for a solution though. If i find one I'll post it here.

                          • 10. Re: Set iteration error: org.hibernate.collection.Persistent
                            elgamal

                            Haven't found a good solution, so I just coded a function that simple gets my Set and stores the elements into a List. In my special case its not a bad idea I think, because the user can only select about 20 applications. Of course in genereal iterating over all Set elements takes quite some time.

                            Adam Winer has written a nice Class for exactly that issue. Check it out at http://sfjsf.blogspot.com/2006/03/usings-sets-with-uidata.html. I have not tested it, but it looks nice ;-)