I've been having a lot of Hibernate. I've been trying both Hibernate interfaces and JPA-only interfaces. In all cases I get an "org.hibernate.SessionException: Session is closed!" (possibly wrapped in a javax.persistence.PersistenceException, when using JPA only interfaces). This error is thrown on the first access to the EntityManager or Session.
Under most cases, I've been creating the EntityManagerFactory via Spring and then marking a setEntityManager with @PersistenceContext.
Initially I thought it was problems with the casting the EntityManager to a HibernateEntityManger to get at the underlying Session (to write a query by Criteria method, while still using JPA for injection. However when I switched to using a plain vanilla createQuery on the entityManager, I still get the session is closed error.
This happens in either production code or in
test code. In the production code its called in an
Struts 2 Action. (Ie its not a lazy loading in view, etc).
The queries are the initial operation I'm trying to do on the session. When I start trying to trace through and debug, the first time I get the Session, I can see its already closed.
How do I figure out why the sessions are opening in a closed state?