Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 226
ariel_ro Avatar asked Apr 17 '26 09:04

ariel_ro


1 Answers

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.

like image 124
Sean Patrick Floyd Avatar answered Apr 18 '26 21:04

Sean Patrick Floyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!