Given the two line of code :
entityManager.find(MyEntity.class, myId);
((Session) getEntityManager().getDelegate()).load(MyEntity.class, myId);
The first instruction works fine, but the second one throws org.hibernate.SessionException: Session is closed!. Any idea ?
Context : spring batch 3.0.6 / hibernate 3.5.0
Info : EntityManager is injected :
@PersistenceContext
protected EntityManager entityManager;
Update 1
I can see in the find method a call to this.getSession() that open a new session if the session is null(in EntityManagerImpl.getRawSession)
Update 2
In the second situation the getSession method is not call but a class called SharedEntityManagerCreator that close the session :
if(isNewEm) {
EntityManagerFactoryUtils.closeEntityManager(target1);
}