Hibernate 4.2.4 and JPA 2.1

I have small web application with RESTful Web Services: https://github.com/kyryloholodnov/niagara/tree/master/JavaEE7WebServices

It was deployed on Glassfish 4 and used EclipseLink JPA 2.1.

But a few days ago I decided to change JPA provider to Hibernate. The last final version of hibernate-core and hibernate-entitymanager was 4.2.4.Final. After removing all EclipseLink dependencies and adding hibernate-corehibernate-entitymanager v4.2.4.Final (and editing persistence.xml of course), my web application was built and deployed sucessfully on GlassFish 4.

But if I moved to /webresources/esrole/count page, I got the following error (the part of stacktrace below):

“…Caused by: java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(Ljavax/persistence/SynchronizationType;Ljava/util/Map;)Ljavax/persistence/EntityManager;…”

After searching, I found the similar bug: https://hibernate.atlassian.net/browse/HHH-8308

This means that Hibernate 4.2.x does not support JPA 2.1, but 2.0: method EntityManagerFactory.createEntityManager(javax.persistence.SynchronizationType, java.util.Map) appeared in JPA 2.1 and is not supported by Hibernate 4.2.x.

After replacing 4.2.4.Final to 4.3.0.Beta3 in pom.xml, this problem disappeared as expected. But when I moved to /webresources/esrole/count, I got NullPointerException that is not related to injecting PersistenceContext into my Stateless bean:

“…java.lang.NullPointerException
at org.hibernate.engine.transaction.internal.jta.JtaStatusHelper.getStatus(JtaStatusHelper.java:73)…”

The solution was here: https://community.jboss.org/thread/177282

After placing this property: <property name=”hibernate.transaction.jta.platform” value=”org.hibernate.service.jta.platform.internal.SunOneJtaPlatform” /> into persistence.xml, my page /webresources/esrole/count was loaded and executed sucessfully.

6 thoughts on “Hibernate 4.2.4 and JPA 2.1

  1. I could not make it work even after adding this property. I’m using glassfish 4.0. Can you point me in the right direction ?

    1. Hi, Priyam.
      Could you please provide me with information about exceptions, artifacts versions (pom.xml if you use Maven), persistence.xml and another information that may be helpful for investigation?
      Thank you!

  2. Funciona de maravilla con hibernate 4.3.4 + la propiedad <property name=”hibernate.transaction.jta.platform” value=”org.hibernate.service.jta.platform.internal.SunOneJtaPlatform”

Leave a comment