1 Reply Latest reply on Sep 28, 2012 9:21 AM by Adam Warski

    Problem with closing EntityManager when using Hibernate Session

    Rajesh Kumar Newbie

      Hi All


      I am using Hibernate with JPA in Jboss 7.1.


      I created my Hibernate session using the following codings


      EntityManagerFactory emf = Persistence.createEntityManagerFactory("test");
      EntityManager em = emf.createEntityManager();
      Session s = em.unwrap(Session.class); 


      It is working fine.

      Now at the end when I was trying to close the Session and EntityManager



      if(em.isOpen()) {


      I get below exception while closing the EntityManager.



      ERROR [stderr] (MSC service thread 1-3) 
      org.hibernate.SessionException: Session was already closed
      ERROR [stderr] (MSC service thread 1-3) 
      at org.hibernate.internal.SessionImpl.close(SessionImpl.java:266)
      ERROR [stderr] (MSC service thread 1-3) 
      at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:152)


      Can anyone identify the problem ?

      Thanks in advance.