3 Replies Latest reply on Nov 4, 2005 7:18 AM by Viet

    Closing hibernate sessions

    Martin Giljohann Newbie

      Hello, I have a question concerning hibernate with the portal. For my application I followed
      http://docs.jboss.org/jbossas/getting_started/v4/html/hibernate.html
      and deploy the mappings inside a *.har, which is inside an *.ear - no problem.

      To get the Session I'm using JBP code from org.jboss.portlet.forums.impl.ForumsModuleImpl#getSession

      SessionFactory sf = (SessionFactory)new InitialContext().lookup("java:/portal/SessionFactory");
       Session session = sf.getCurrentSession();
       return session;
       }
       catch (NamingException e)
       {
       throw new RuntimeException(e);
       }


      For the queries I looked at other methods from ForumsModuleImpl and I saw that the sessions are never closed here. However in the above linked docs they are closed in a finally block. Is this not necessary because the container somewhat takes care about this?

      Thanks
      Martin