"java.lang.ClassCastException: org.hibernate.internal.SessionFactoryImpl cannot be cast to org.hibernate.jpa.internal.EntityManagerFactoryImpl" using Hibernate in JBoss EAP
Issue
Application code creates an entity manager factory via Persistence.createEntityManagerFactory(String) using the code below:
import org.hibernate.jpa.internal.EntityManagerFactoryImpl;
...
EntityManagerFactoryImpl entityManagerFactory = (EntityManagerFactoryImpl) Persistence.createEntityManagerFactory( "my-unit" );
This results in an exception:
... java.lang.ClassCastException: org.hibernate.internal.SessionFactoryImpl cannot be cast to org.hibernate.jpa.internal.EntityManagerFactoryImpl
at org.myco.MyClass.unwrap(MyClass.java:99)
...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.3
- 7.2
- Hibernate 5.3
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.