I use the unwrap() method as a bridge to make old hibernate code runnable on top of JPA classes while migrating. I keep track of EntityManager creation and closing like the SessionContext used in Hibernate.
But if legacy code closes the Session the EntityManager.isOpen() still returns true and after calling close() I get an Exception that the Session was already closed.
I noticed this may be the source of the error:
{ noformat code:title=org.hibernate.jpa.internal.EntityManagerImpl.isOpen() } public boolean isOpen() { //adjustFlushMode(); //don't adjust, can't be done on closed EM checkEntityManagerFactory(); try { if ( open ) { internalGetSession().isOpen(); //to force enlistment in tx } return open; } catch (HibernateException he) { throwPersistenceException( he ); return false; } } { noformat code }
Should this method look like this?
{ noformat code:title=Fixed version of org.hibernate.jpa.internal.EntityManagerImpl.isOpen() } public boolean isOpen() { //adjustFlushMode(); //don't adjust, can't be done on closed EM checkEntityManagerFactory(); try { return open && internalGetSession().isOpen(); //to force enlistment in tx } catch (HibernateException he) { throwPersistenceException( he ); return false; } } { noformat code } |
|