在我的应用程序中实现JPA 2.0时遇到了一些问题。我正在使用条件查询,并且我需要从EntityManager获取会话。我用下面的方法(根据this)会话ses = entityManager.unwrap(Session.class);
在Tomcat 7.0.8上运行后,我得到了以下结果:
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)此外,我还引用了以下与Hibernate相关的依赖项(我怀疑问题出在哪里):
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对此有什么想法吗?
发布于 2011-08-09 23:03:17
Hibernate 3.4.x与JPA-2不兼容。JPA2 was first supported in Hibernate Entitymanager 3.5.0。
您得到的错误意味着ClassLoader找不到您正在访问的接口方法的实现方法,如果底层实现只符合JPA-1,这是很有意义的,因为在JPA2中已经添加了unwrap。
发布于 2017-08-03 02:24:34
我使用的是旧版本的Hibernate (3.3.0)和最新版本的OpenEJB (4.6.0)。我的解决方案是:
EntityManagerImpl entityManager = (EntityManagerImpl)em.getDelegate();
Session session = entityManager.getSession();https://stackoverflow.com/questions/6994031
复制相似问题