3

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?

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
ariel_ro
  • 33
  • 1
  • 4

2 Answers2

4

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.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • 1
    Solved it! Downloaded the latest hibernate jars from hibernate.org. Also, I had an ejb3-persistence.jar in my classpath which had the same package name AND was before hibernate-jpa-2.0 jar in the build path order. That jar didn't implement JPA 2.0 specification. – ariel_ro Aug 10 '11 at 12:46
0

I'm using an old version of Hibernate (3.3.0) with a newest version of OpenEJB (4.6.0). My solution was:

EntityManagerImpl entityManager = (EntityManagerImpl)em.getDelegate();
Session session = entityManager.getSession();
Dherik
  • 17,757
  • 11
  • 115
  • 164