Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-16433

[GSS](7.2.z) HHH-13281: java.lang.ClassCastException: org.hibernate.internal.SessionImpl cannot be cast to org.hibernate.ejb.HibernateEntityManager

XMLWordPrintable

    • +
    • Workaround Exists
    • Hide

      In Hibernate 5.3, the entity manager can be unwrapped directly to Session and this is appropriate moving forward as the additional layer of indirection provided by HibernateEntityManager offers no additional benefit.

      org.hibernate.Session session = entityManager.unwrap(org.hibernate.Session.class);
      
      Show
      In Hibernate 5.3, the entity manager can be unwrapped directly to Session and this is appropriate moving forward as the additional layer of indirection provided by HibernateEntityManager offers no additional benefit. org.hibernate.Session session = entityManager.unwrap(org.hibernate.Session.class);

      The code below worked in Hibernate 5.1 and earlier releases

      org.hibernate.ejb.HibernateEntityManager em = entityManager.unwrap(org.hibernate.ejb.HibernateEntityManager.class);
      

      In Hibernate 5.3, the same code fails with:

      java.lang.ClassCastException: org.hibernate.internal.SessionImpl cannot be cast to org.hibernate.ejb.HibernateEntityManager
             at support.hibernate.entity.TestHibernate.test(TestHibernate.java:56)
      

              gbadner@redhat.com Gail Badner (Inactive)
              rhn-support-sfikes Stephen Fikes (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: