1 2 Previous Next 17 Replies Latest reply on Aug 11, 2008 9:15 PM by Tony Herstell

    Lazy Exceptions

    Tony Herstell Master

      Sorry for cross post but it seems to be more Seam than Richfaces question (I think).

      Richfaces Forum Topic

        • 1. Re: Lazy Exceptions
          Tony Herstell Master

          Now I get it when I use a checkbox with Ajax to redraw less in the list.
          This time its lookingfor Roles and I dont even access Roles!

          javax.faces.FacesException: javax.el.ELException: /pages/user/userList.xhtml @109,79 rendered="#{userListController.isShowingEmail() eq true}": org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: nz.co.selwynequestriancentre.model.entity.User.roles, no session or session was closed
               at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:373)
               at org.richfaces.component.DataIterator.nextColumn(DataIterator.java:27)
               at org.richfaces.component.ColumnsIterator.next(ColumnsIterator.java:40)
               at org.richfaces.component.ColumnsIterator.next(ColumnsIterator.java:14)
               at org.ajax4jsf.component.UIDataAdaptor.saveChildState(UIDataAdaptor.java:893)
               at org.ajax4jsf.component.UIDataAdaptor.setRowKey(UIDataAdaptor.java:346)
               at org.richfaces.renderkit.AbstractRowsRenderer.process(AbstractRowsRenderer.java:85)
               at org.ajax4jsf.model.SequenceDataModel.walk(SequenceDataModel.java:101)
               at org.richfaces.model.ModifiableModel.walk(ModifiableModel.java:118)
               at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:1127)
               at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:106)
               at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:91)
               at org.richfaces.renderkit.AbstractRowsRenderer.encodeChildren(AbstractRowsRenderer.java:138)
               at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
               at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:125)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:68)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:116)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:68)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:116)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:68)
               at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:116)
               at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
               at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:673)
               at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:544)
               at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
               at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
               at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
               at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
               at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
               at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
               at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)

          Roles are not even lazilly fetched from User.

              public List<SelwynEquestrianCentreRole> getRoles() {
                    return roles;
               public void setRoles(List<SelwynEquestrianCentreRole> roles) {
                    this.roles = roles;

          • 2. Re: Lazy Exceptions
            Tony Herstell Master

            just to clarify.
            This is when I move onto next page using rich:datascroller

            • 3. Re: Lazy Exceptions
              Daniel Hinojosa Master

              What is the scope of nz.co.selwynequestriancentre.model.entity.User?

              • 4. Re: Lazy Exceptions
                Tony Herstell Master

                Default... whatever that is?
                Humm..what would it be and why is that important??

                Image and Role are also Default.

                @Role(name="userSearchCriteria", scope=SESSION)

                 * @author Tony Herstell 
                 * @version $Revision: 1.11 $ $Date: 2008-02-28 12:49:26 $ 
                @Role(name="userSearchCriteria", scope=SESSION)
                public class User implements Serializable {
                    private Long id;
                    private Integer version; // Hiberante Docs: EJB3 sais Timestamp actually but recommend Integer
                    private String surname;
                    private String firstname;
                    private String password;
                    private String email;
                    private boolean emailContactOk = true;
                    private String homePhone;
                    private String mobilePhone;
                    private boolean phoneContactOk = true;
                    private boolean dressageJudge = false;
                    private boolean dressageWriter = false;
                    private boolean dressageHelper = false;
                    private boolean sjJudge = false;
                    private boolean sjHelper = false;
                    private boolean showingJudge = false;
                    private boolean showingHelper = false;
                    private boolean eventsHelper = false;
                    private boolean termsApproved = false;
                    private List<SelwynEquestrianCentreRole> roles;
                    private Image avatar;
                    private MaintenanceDates maintenanceDates;
                    private List<Booking> bookings;

                • 5. Re: Lazy Exceptions
                  Daniel Hinojosa Master

                  What about UserListController?
                  Entities are conversation scope by default.  The inevitable solution is going to be to figure out what scopes everything is, and why they shut down earlier than you expect them to.

                  • 6. Re: Lazy Exceptions
                    Tony Herstell Master

                    UserListController is conversational; even tried it as a stateless bean but that made matters worse; not better. It could have been stateless as I only wanted to lauch conversations for CRUD from it and didn't care if when I got back to the user list it had to re-fetch it (performace is not a big issue for this project and I could refactor it to be session scoped and stateful later).

                    I will go through all contributing stuff tonight and see if anything is not convesational.

                    It really seems like these are involved it the problem

                    private List<SelwynEquestrianCentreRole> roles;
                        private Image avatar;

                    maintenanceDates are an embedded entity in the user entity so for all intents and purposes it's in the user entity. This has never caused a problem

                    private MaintenanceDates maintenanceDates;

                    Most Seam example I have seen don't go down lower than 1 entity deep so I dont have much to go on... and Datatable and DataScroller being components mean there is little I can work through.

                    I will also try removing the above parts of the User entity and see if that gets me further... it seem that the User entity is becoming detached (for some reason); so when access is made to the role or avatar Seam Barfs.

                    This pattern I have used before in ICEFaces and it worked perfectly and I still have the option of using the ICEFaces datatables; just wanted to upskill on both Component sets...

                    I have come across this before ages ago, and re-read the entity to get an attached copy, but this seems totally inefficient for the whole user list... I need to fix this (probably flaws in my knowledge of Seam and how it all hangs together) this time.

                    Thanks for your support Dan.

                    • 7. Re: Lazy Exceptions
                      Daniel Hinojosa Master

                      Ok, just do a review of your components.  Somewhere along the way one of your beans is going out of scope causing your entity to become detached.

                      • 8. Re: Lazy Exceptions
                        Tony Herstell Master

                        I usually have a log.info on the @Destroy method of my beans.

                        Ill ensure I have them all in place (even the entities if I can!).

                        At least I have somehere to look now.


                        • 10. Re: Lazy Exceptions
                          Tony Herstell Master

                          Possible Seam Bug

                          Did you have apeek at this?

                          Is that what I am being hammered by?

                          • 11. Re: Lazy Exceptions
                            Daniel Hinojosa Master

                            Are you using a Seam 1.1.x? or Seam 2.x?

                            The term @Conversional I think is old as for 2.x, and may not be supported.  It's now @Scope(type=ScopeType.CONVERSATION).

                            The other blaring red flag is:

                                 private EntityManager em;

                            That isn't stateful. Therefore once you get an entity you can no longer ask it for more information, it immediately becomes detached.  You need to make that an EXTENDED context or better yet, make it SMPC (Seam Managed Persistence Context) to have more functionality.

                            • 12. Re: Lazy Exceptions
                              Tony Herstell Master

                              Using Latest Seam proddie and RF.

                              oh! When did all that change? I skipped a few months a while back (was working with Construction team driving big diggers/scrapers etc.) and doing Wiring/Building etc. on the Equestrian Centre.

                              If its deprecated why no warnings in the serverlog... I will check!

                              > make it SMPC (Seam Managed Persistence Context) to have more functionality

                              Err.. Yes my bad for foreggting about EXTENDED but SMPC.. whats that ! I will have read up on that tonight.


                              • 13. Re: Lazy Exceptions
                                Daniel Hinojosa Master

                                Ooops, yeah @Conversational is still good, my mistake.

                                From Seam in Action..

                                If you want to enforce that a component or method only be used within the scope of a long-
                                running   conversation,   annotate   the  component       class   or  the  method with the
                                @Conversational annotation, summarized in table 7.5. Seam verifies that the
                                conversation is long-running before permitting a call to the following method:
                                    @Conversational public String saveBasicCourseInfo() { ... }
                                If an attempt is made to execute a @Conversational method outside the presence of a
                                long-running conversation, Seam will raise the org.jboss.seam.noConversation event
                                and then throw the runtime exception NoConversationException.

                                SMPC - is Seam Managed Persistence Context.  Its just like EXTENDED but with more features to it.

                                • 14. Re: Lazy Exceptions
                                  Tony Herstell Master

                                  No Worries mate.

                                  I only met one person that never makes mistakes and knows everything.
                                  After marrying her I just sold the Encyclopedia Britannica.

                                  Looking up SMPC in the doco now.

                                  If this works I am going to be SOOO happy; in anticipation I already gave you a few stars!


                                  1 2 Previous Next