• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sessions being opened in a closed state...

 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done some more debugging, and I don't seem to be any closer to a solution. I have tried modifying my connection string/username/password details on the data source.

When I put in a non-existant database name, I receive the same exception, but there's an added exception in the logs where Spring is configuring the beans, as well as on the database console. Ditto if I put in a non-existant user. So I think this tells me that when I don't get those exceptions from spring, its successfully connecting to the database.

And I'm back to wondering why the sessions are being returned in a closed state....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic