1 Reply Latest reply on Apr 4, 2005 7:19 PM by Marco Antonio Villalobos, Jr.

    [Hibernate] Session cannot be generated outside of transacti

    Marco Antonio Villalobos, Jr. Newbie

      subject: [Hibernate] Session cannot be generated outside of transaction scope


      I have Stateless session bean that utilizes container managed transactions. This particular method requires a transaction. I am using Hibernate for dataaccess.

      my code is as follows:

      private String getSessionFactoryContext() throws NamingException
       String value = null;
       Context ctx = new InitialContext();
       Context environment = (Context)ctx.lookup("java:comp/env");
       value = (String) environment.lookup("sessionFactory");
       return value;
      public Session getCurrentSession(String sessionFactory)
       return HibernateContext.getSession(sessionFactory);
      public ValueObject myEJBBusinessMethod()
       Session session = getCurrentSession(getSessionFactoryContext());

      When I call the myEJBBusinessMethod I get the error, the first
      line throws an exception with the following detailed message:

      "Session cannot be generated outside of transaction scope"

      I am simply trying to use container managed transactions
      within a remote stateless session bean with my session bean
      using hibernate, but I get that error, does
      anybody have a code example about the proper configuration.

      I already spent about 5 hours trolling for the answer.