Search code examples
javahibernatejpajpa-2.0hibernate-entitymanager

EntityManager.unwrap() throws java.lang.AbstractMethodError


I'm having some issues implementing JPA 2.0 in my app. I'm using Criteria queries and I need to grab the session from the EntityManager. I do it in the following way (according to this) Session ses = entityManager.unwrap(Session.class);

After running on top of Tomcat 7.0.8 I get the following:

Struts has detected an unhandled exception:
# Messages:     org.hibernate.ejb.EntityManagerImpl.unwrap(Ljava/lang/Class;)Ljava/lang/Object;

Stacktraces 
java.lang.reflect.InvocationTargetException
java.lang.AbstractMethodError: org.hibernate.ejb.EntityManagerImpl.unwrap(Ljava/lang/Class;)Ljava/lang/Object; sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Also I'm referencing the following Hibernate-related dependencies (where I suspect the problem is):

hibernate-3.2.5.ga.jar
hibernate-annotations-3.4.0.GA.jar
hibernate-commons-annotations-3.1.0.GA.jar
hibernate-core-3.3.0.GA.jar
hibernate-entitymanager-3.4.0.GA.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar

Any idea about this?


Solution

  • Hibernate 3.4.x is not JPA-2 compliant. JPA 2 was first supported in Hibernate Entitymanager 3.5.0.

    The error you are getting means that the ClassLoader can't find the implementation method for the interface method you are accessing, which makes perfect sense if the underlying implementation is only JPA-1 conform, since unwrap has been added in JPA 2.