-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: JBoss, Struts, EJB, DAO Help
PostPosted: Sun Jan 23, 2005 6:57 pm 
Newbie

Joined: Sun Jan 23, 2005 6:29 pm
Posts: 3
Hello all,

I have beat my brain to death over the last week on how all this works and if I'm doing the following correctly. Any help or direction would be GREATLY appreciated. I have read all the JBoss and Hibernate Wiki's and forums along with scouring the web for any information on how to properly build a J2EE application using EJB's, Hibernate and JBoss, but still can not get past the
Code:
[LazyInitializationException] Failed to lazily initialize a collection - no session or session was closed
exception when calling a getCollection method inside a JSP.

Here is my current architecture. I am building a Struts application under JBoss. My action class is calling a EJB which in turn calls a DAO that uses hibernate to return user information from a database.

    JBoss 4.0.1
    JBoss Hibernate JMX MBean 2.1.6
    MSSQL 2000

Here is my action class method that gets the User object and stores it in the session scope:
Code:
    public ActionForward select(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws IOException, ServletException {

        // Default target to success
        String target = new String("success");
       
        UserSelectForm userSelect = (UserSelectForm) form;
        int userID = Integer.parseInt(userSelect.getUserID());
       
        userService = new UserServiceClient();

        try {       

            userService.setUserID(userID);
            User user = userService.getUserByID();
           
            request.getSession().setAttribute("userDetail", user);
           
            log.info("Set Request Attribute userDetail for User ID: " + user.getUserID());
        } catch (ClassCastException ex) {
            log.error("ClassCastException", ex);
            target = new String("failure");
        }

        // Forward to the appropriate View
        return (mapping.findForward(target));
      }


The action class calls a UserService class which is used to call the EJB. Here is the UserService method:
Code:
    private static UserService getUserServiceEJB() {
        UserService userService = null;
       
        try {       
            InitialContext ctx = new InitialContext();
            Object ejb = ctx.lookup("ejb/UserService");
            UserServiceHome home = (UserServiceHome)PortableRemoteObject.narrow(ejb, UserServiceHome.class);
            userService = home.create();
        } catch (NamingException ex) {
            log.error("NamingException", ex);
        } catch (ClassCastException ex) {
            log.error("ClassCastException", ex);
        } catch (CreateException ex) {
            log.error("CreateException", ex);
        } catch (RemoteException ex) {
            log.error("RemoteException", ex);
        }
        return userService;
    }
   
    public User getUserByID() {
        User user = null;
       
        try {       
            user = (User) getUserServiceEJB().getUserByID(this.userID);
        } catch (ClassCastException ex) {
            log.error("ClassCastException", ex);
        } catch (RemoteException ex) {
            log.error("RemoteException", ex);
        }
        return user;
    }


Here is the EJB method that it calls:
Code:
   public User getUserByID(int id) {
      User user = null;
        try {
          UserDAO userDAO = new UserDAO();
          user = userDAO.getUserById(id);
          HibernateUtil.commitTransaction();
        } catch (InfrastructureException ex) {
             throw new InfrastructureException(ex);
        } finally {
             HibernateUtil.closeSession();
        }
      return user;
    }


And finally, here is the DAO that abstracts the data layer:
Code:
    public UserDAO() {
        HibernateUtil.beginTransaction();
    }

    public User getUserById(int userID) {
        Session session = HibernateUtil.getSession();
        User user = null;
        try {
            user = (User) session.createCriteria(User.class).add(Expression.eq("userID", new Integer(userID))).uniqueResult();
                       
        } catch (HibernateException ex) {
            throw new InfrastructureException(ex);
        }
        return user;
    }


Now all this works fine and the User object is returned to the view and I can access its properties using standard JavaBean syntax until I try to access a collection of groups that this user belongs to. Once I call the
Code:
getGroups()
method I recieve the following:

Code:
16:36:16,779 ERROR [LazyInitializationException] Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
   at net.sf.hibernate.collection.Set.iterator(Set.java:130)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:329)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:205)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:137)
   at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:227)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_forEach_1(userDetail_jsp.java:1789)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_if_6(userDetail_jsp.java:1762)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_html_form_2(userDetail_jsp.java:1696)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_if_5(userDetail_jsp.java:1635)
   at org.apache.jsp.admin.userDetail_jsp._jspService(userDetail_jsp.java:197)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:510)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
   at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:581)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:101)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:137)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:758)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:890)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
   at org.apache.jsp.layout_jsp._jspx_meth_tiles_insert_2(layout_jsp.java:234)
   at org.apache.jsp.layout_jsp._jspService(layout_jsp.java:120)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)
16:36:16,779 ERROR [Engine] ApplicationDispatcher[/webapp-struts_tiles_securityfilter] Servlet.service() for servlet jsp threw exception
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
   at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:209)
   at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
   at net.sf.hibernate.collection.Set.iterator(Set.java:130)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:329)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:205)
   at org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:137)
   at javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:227)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_forEach_1(userDetail_jsp.java:1789)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_if_6(userDetail_jsp.java:1762)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_html_form_2(userDetail_jsp.java:1696)
   at org.apache.jsp.admin.userDetail_jsp._jspx_meth_c_if_5(userDetail_jsp.java:1635)
   at org.apache.jsp.admin.userDetail_jsp._jspService(userDetail_jsp.java:197)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:510)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
   at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:581)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:101)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:137)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:758)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:890)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
   at org.apache.jsp.layout_jsp._jspx_meth_tiles_insert_2(layout_jsp.java:234)
   at org.apache.jsp.layout_jsp._jspService(layout_jsp.java:120)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)
16:36:16,779 ERROR [InsertTag] ServletException in '/admin/userDetail.jsp': Failed to lazily initialize a collection - no session or session was closed
org.apache.jasper.JasperException: Failed to lazily initialize a collection - no session or session was closed
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
   at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:510)
   at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
   at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:581)
   at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:101)
   at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:137)
   at org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:758)
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:890)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
   at org.apache.jsp.layout_jsp._jspx_meth_tiles_insert_2(layout_jsp.java:234)
   at org.apache.jsp.layout_jsp._jspService(layout_jsp.java:120)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)
16:36:16,789 ERROR [Engine] ApplicationDispatcher[/webapp-struts_tiles_securityfilter] Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: ServletException in '/admin/userDetail.jsp': Failed to lazily initialize a collection - no session or session was closed
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
   at org.apache.jsp.layout_jsp._jspx_meth_tiles_insert_2(layout_jsp.java:234)
   at org.apache.jsp.layout_jsp._jspService(layout_jsp.java:120)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)
16:36:16,789 ERROR [Engine] StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
javax.servlet.jsp.JspException: ServletException in '/admin/userDetail.jsp': Failed to lazily initialize a collection - no session or session was closed
   at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
   at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
   at org.apache.jsp.layout_jsp._jspx_meth_tiles_insert_2(layout_jsp.java:234)
   at org.apache.jsp.layout_jsp._jspService(layout_jsp.java:120)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
   at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
   at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
   at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
   at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
   at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
   at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
   at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
   at java.lang.Thread.run(Thread.java:595)


I understand that by abstracting the data layer in my DAO that it is closing the session before my JSP is calling the collection. I have read all posts and wiki's and see reference to implementing some sort of Interceptor or Servlet Filter that manages the request but can't find an actual example as I have not designed on of these components before. I can't imagine that one would want to embed this logic into the view or controller layer. I know there has to be an solution as JBoss and Hibernate combinations are in production everywhere.

Please respond with any suggestions or that you may have. Please be gentle as this is my first post. Thanks in advance!!!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 23, 2005 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The collection is lazy so you can solve this issue by fetching the collection eagerly, eg,

Code:
user = (User) session.createCriteria(User.class)
    .setFetchMode("groups", FetchMode.EAGER)
    .add(Expression.eq("userID", new Integer(userID)))
    .uniqueResult();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 23, 2005 8:04 pm 
Newbie

Joined: Sun Jan 23, 2005 6:29 pm
Posts: 3
Thanks David!!!! That seemed to solve my issue except when the collection is empty. I am still getting the same exception if there are no entries in the collection. There will be times when a user does not have any groups at all. So even though the user was fetched EAGERLY, the groups are empty. I tried the following code in my User object to init the groups with an empty HashTable instead of null but this did not work. What is the best way around this?

Code:
public class User {

    private int userID;
    private String username;
    private String email;
    private String firstName;
    private String lastName;
    private String street1;
    private String street2;
    private String city;
    private String state;
    private String zip;
    private String phone1;
    private String phone2;
    private String fax;
    private Set groups = new HashSet();
   
    public User() {}
   
    /**
     * @return Returns the userID.
     * @hibernate.id   column="UserID"
     *       type="int"
     *       generator-class="native"
     */
    public int getUserID() {
        return userID;
    }
    /**
     * @param userID The userID to set.
     */
    public void setUserID(int userID) {
        this.userID = userID;
    }
    /**
     * @return Returns the username.
     * @hibernate.property   column="Username"
     *                   unique="true"
     *                   update="false"
     */
    public String getUsername() {
        return username;
    }
    /**
     * @param username The username to set.
     */
    public void setUsername(String username) {
        this.username = username;
    }
    /**
     * @return Returns the firstName.
     * @hibernate.property   column="FirstName"
     */
    public String getFirstName() {
        return firstName;
    }
    /**
     * @param firstName The firstName to set.
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    /**
     * @return Returns the lastName.
     * @hibernate.property   column="LastName"
     */
    public String getLastName() {
        return lastName;
    }
    /**
     * @param lastName The lastName to set.
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    /**
     * @return Returns the phone1.
     * @hibernate.property   column="Phone1"
     */
    public String getPhone1() {
        return phone1;
    }
    /**
     * @param phone1 The phone1 to set.
     */
    public void setPhone1(String phone1) {
        this.phone1 = phone1;
    }
    /**
     * @return Returns the phone2.
     * @hibernate.property   column="Phone2"
     */
    public String getPhone2() {
        return phone2;
    }
    /**
     * @param phone2 The phone2 to set.
     */
    public void setPhone2(String phone2) {
        this.phone2 = phone2;
    }
    /**
     * @return Returns the city.
     * @hibernate.property   column="Address_City"
     */
    public String getCity() {
        return city;
    }
    /**
     * @param city The city to set.
     */
    public void setCity(String city) {
        this.city = city;
    }
    /**
     * @return Returns the fax.
     * @hibernate.property   column="Fax"
     */
    public String getFax() {
        return fax;
    }
    /**
     * @param fax The fax to set.
     */
    public void setFax(String fax) {
        this.fax = fax;
    }
    /**
     * @return Returns the state.
     * @hibernate.property   column="Address_State"
     */
    public String getState() {
        return state;
    }
    /**
     * @param state The state to set.
     */
    public void setState(String state) {
        this.state = state;
    }
    /**
     * @return Returns the street1.
     * @hibernate.property   column="Address_Street1"
     */
    public String getStreet1() {
        return street1;
    }
    /**
     * @param street1 The street1 to set.
     */
    public void setStreet1(String street1) {
        this.street1 = street1;
    }
    /**
     * @return Returns the street2.
     * @hibernate.property   column="Address_Street2"
     */
    public String getStreet2() {
        return street2;
    }
    /**
     * @param street2 The street2 to set.
     */
    public void setStreet2(String street2) {
        this.street2 = street2;
    }
    /**
     * @return Returns the zip.
     * @hibernate.property   column="Address_Zip"
     */
    public String getZip() {
        return zip;
    }
    /**
     * @param zip The zip to set.
     */
    public void setZip(String zip) {
        this.zip = zip;
    }
    /**
     * @return Returns the email.
     * @hibernate.property   column="Email"
     *                   unique="true"
     */
    public String getEmail() {
        return email;
    }
    /**
     * @param email The email to set.
     */
    public void setEmail(String email) {
        this.email = email;
    }
    /**
     * @return Returns the groups.
     * @hibernate.set               table="User_Groups"
     *    lazy="true"
     * @hibernate.collection-key   column="UserID"
     * @hibernate.collection-many-to-many   column="GroupID"
     *       class="com.xx.xx.model.Group"
     */
    public Set getGroups() {
        return roles;
    }
    /**
     * @param roles The groups to set.
     */
    public void setGroups(Set groups) {
        this.groups = groups;
    }
}


My JSP code excerpt that uses this object:
Code:
<select name="activeRoles" size="7" style="width:150;" multiple="true">
   <%-- Iterate over each group within the userDetail.groups(Set) and    generate an HTML <option> tag for each --%>
   <c:if test="${userDetail.groups != null}">
      <c:forEach items="${userDetail.groups}" var="group">
         <option value="${group.groupID}">${group.groupname}</option>
      </c:forEach>
   </c:if>
</select>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 24, 2005 1:54 pm 
Newbie

Joined: Sun Jan 23, 2005 6:29 pm
Posts: 3
Well, it turns out that if I use the following in my DAO object:
Code:
user = (User) session.createCriteria(User.class)
            .setFetchMode("groups", FetchMode.EAGER)
            .add(Expression.eq("userID", new Integer(userID)))
            .uniqueResult();

This works when the JSP calls the user.getGroups() as long as there are groups in the collection to be returned. If the collection is empty, it still throws the [LazyInitializationException]. I would think that it should just return an empty HashSet. Somehow the c:foreach tag must be trying to call the isEmpty() method of a HashSet and this in turn makes Hibernate want to reconnect the session? But I'm just guessing as I am by no means an expert.

So, for the time being instead of using the code above, I replaced it with the Hibernate.initialize(Object o) method. Like so:
Code:
user = (User) session.createCriteria(User.class).add(Expression.eq("userID", new Integer(userID))).uniqueResult();
Hibernate.initialize(user.getGroups());


Now when my JSP calls the getGroups method, everything works as expected without any exceptions being thrown if the collection is empty.

Is this a correct usage?

Also, is it good practice to do it this way instead of using some sort of Interceptor in JBoss to manage the sessions throughout the request?

Does anyone have an example of setting up an Interceptor to do just this so I won't have to initialize every lazy collection when I need it?

Thanks!!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.