将 Glassfish v2 升级到 JPA 2.0?
我尝试在 Glassfish V2 上将 Hibernate 3.5.5 与 Spring HibernateJpaVendorAdapter 一起使用,但在初始化 Spring 上下文时出现以下异常:
java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39) 在org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:517) 在 org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
问题是 Glassfish V2 使用 JPA1.0,它在 hibernate-jpa-2.0-api-1.0.0.Final.jar 之前加载到服务器类路径上随 Hibernate 一起提供。 JPA 1.0 在 PersistenceUnitInfo 中没有 getSharedCacheModel 方法,但 JPA 2.0 有。
有没有办法升级 Glassfish V2 以使用 JPA 2.0(或此问题的任何其他解决方案)?
干杯,
J
I'm trying to use Hibernate 3.5.5 with Spring HibernateJpaVendorAdapter on Glassfish V2 but I'm getting the following exception when the Spring context is initialised:
java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getSharedCacheMode()Ljavax/persistence/SharedCacheMode;
at org.hibernate.ejb.util.LogHelper.logPersistenceUnitInfo(LogHelper.java:39)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:517)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
The problem is that Glassfish V2 uses JPA1.0 which is loaded on the server classpath before hibernate-jpa-2.0-api-1.0.0.Final.jar which ships with Hibernate. JPA 1.0 doesn't have a getSharedCacheModel method in PersistenceUnitInfo but JPA 2.0 does.
Is there any way of upgrading Glassfish V2 to use JPA 2.0 (or any other solution to this problem)?
Cheers,
J
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以尝试将 JPA 2.0 jar 放在
/domain/lib/endorsed
目录中You can try putting the JPA 2.0 jar in the
/domain/lib/endorsed
dir感谢大家的反馈。将 jpa jar 放入 /domain/lib/endorsed 对我有用。
设置...
...对我不起作用,尽管这可能只是因为这些类是 javax.
我还尝试剥离 Spring 的 JPATemplate 并直接使用 JPA @PersistenceContext EntityManager - 但这导致了各种各样的问题。 Glassfish v2 + Spring + Hibernate 不是朋友!
Thanks for the feedback guys. Putting the jpa jar in /domain/lib/endorsed worked for me.
Setting...
...did not work for me although that could just be because the classes are part of javax.
I also tried stripping out Spring's JPATemplate and using the JPA @PersistenceContext EntityManager directly - this caused all sorts of problems though. Glassfish v2 + Spring + Hibernate are not friends!
据我所知,通过简单地替换库并使用容器管理的 JPA 2.0 EntityManager 来升级 Java EE 5 容器核心 JPA 库是不可能的。
但是,应该可以将 JPA 2.0 实现与应用程序级别提供的 JPA 2.0 API 库结合使用,并使用应用程序管理 JPA 2.0 EntityManager。
要尝试使用 GlassFish v2 的第二种方法,您需要关闭类加载器委托(以便首先使用应用程序库)。这可以在您将打包在
WEB-INF
下的sun-web.xml
中进行配置:To my knowledge, it is not possible to upgrade Java EE 5 containers core JPA libraries by simply replacing libraries and to use a container managed JPA 2.0 EntityManager.
However, it should be possible to use a JPA 2.0 implementation with the JPA 2.0 API library provided at the application level and to use an application managed JPA 2.0 EntityManager.
To try the second approach with GlassFish v2, you'll need to switch off classloader delegation (so that application libraries will be used first). This can be configured in a
sun-web.xml
that you'll packaged underWEB-INF
:Glassfish 2.1 不支持 JPA 2,我下载了 JPA 2 版本并粘贴到 $GLASSFISH_HOME/lib/endorsed/ 目录中,然后粘贴到 commons-loggin1.1.jar 中,这可以工作为我。
它看起来像这样:
/glassfish/lib/endorsed$ ls
激活.jar
openjpa-all-2.0.1.jar
commons-logging-1.1.jar
webservices-api.jar
http://glassfish.java.net/public/comparing_v2_and_v3.html
http://openjpa.apache.org/downloads.html
Glassfish 2.1 don't support JPA 2, I downloaded the JPA 2 version and pasted into the
$GLASSFISH_HOME/lib/endorsed/
directory, and pasted to the commons-loggin1.1.jar, and this works for me.It looks like this:
/glassfish/lib/endorsed$ ls
activation.jar
openjpa-all-2.0.1.jar
commons-logging-1.1.jar
webservices-api.jar
http://glassfish.java.net/public/comparing_v2_and_v3.html
http://openjpa.apache.org/downloads.html