"java.lang.ClassCastException: org.hibernate.internal.SessionFactoryImpl cannot be cast to org.hibernate.jpa.internal.EntityManagerFactoryImpl" using Hibernate in JBoss EAP

Solution Verified - Updated -

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.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content