I am working on a migration of an application from Hibernate/OpenEJB/TomEE to Hibernate/JBoss and I have this exception at runtime:
java.lang.ClassCastException: org.hibernate.internal.SessionImpl cannot be cast to org.hibernate.ejb.EntityManagerImpl
While running this code:
...
import javax.persistence.EntityManager;
...
@PersistenceContext(...)
protected EntityManager em;
...
EntityManagerImpl hibernateEntityManagerImpl = (EntityManagerImpl)em.getDelegate();
Session sess = hibernateEntityManagerImpl.getSession();
...
The same code is working in TomEE. I don't know why the getDelegate()
method does not return an EntityManager as an underlying object.
NB:
- The application is already with hibernate (with lawer version) before and I am just migrating it to JBoss;
- I am using Hibernate 4.2.21.Final (same version for EntityManager);
- persistence.xml provider is
org.hibernate.ejb.HibernatePersistence
Thanks for your help.