Websphere 7 EntityManagerFactory 创建问题
我正在开发一个maven项目,它使用seam 2.2.0、hibernate 3.5.0-CR-2作为JPA提供程序、DB2作为数据库服务器和Websphere 7作为应用程序服务器。现在我面临着以下问题:
- 在我的也被视为SEAM组件的EJB中,我想使用EJB容器中的EntityManager(@PersistenceContext private EntityManager em)而不是Seam的EntityManager(@In private EntityManager em)。但这就是问题,我无法使用@PersistenceContext 获取EntityManager。
在服务器日志上,它表示无法创建 EntityManagerFactory 并收到 ClassCastException:
java.lang.ClassCastException:org.hibernate.ejb.HibernatePersistence 与 javax.persistence.spi.PersistenceProvider 不兼容
经过大量调试和在论坛上搜索后,我假设问题是 Websphere 不使用 Hibernate JPA 提供程序。
有没有人遇到过这个问题并有解决方案?我已经为我的应用程序配置了 WAS 类加载器顺序,以首先使用应用程序类加载器加载类,并且我已将所有必要的 jar 打包到应用程序耳朵中,如下所示: WAS 信息中心:EJB 功能3.0开发。如果有必要,我将发布我的 persistence.xml、components.xml 文件和堆栈跟踪。
我发现这里也讨论了这个问题:
任何提示都会有用。
预先感谢!
米哈埃拉
I'm working on a maven project which uses seam 2.2.0, hibernate 3.5.0-CR-2 as JPA provider, DB2 as database server and Websphere 7 as application server. Now I'm facing de following problem:
- In my EJBs that are seen also as SEAM components I want to use the EntityManager from EJB container (@PersistenceContext private EntityManager em) not Seam's EntityManager (@In private EntityManager em). But this is the problem, I cannot obtain an EntityManager using @PersistenceContext.
On server logs it sais that it cannot create an EntityManagerFactory and gets a ClassCastException:
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence incompatible with javax.persistence.spi.PersistenceProvider
After a lot of debugging and searching on forums I'm assuming that the problem is that Websphere doesn't use the Hibernate JPA provider.
Has anyone faced this problem and has a solution? I configured already WAS class loader order for my application to load the classes with the application class loader first and I\ve packed all necessary jars in application ear as written in: WAS InfoCenter: Features for EJB 3.0 development . If necessary I'll post my persistence.xml, components.xml files and stack trace.
I've found this problem discussed also here:
- Websphere EntityManagerFactory creation problem
- Hibernate 3.3 fail to create entity manager factory in Websphere 7.0. Please help
Any hint will be useful.
Thanks in advance!
Mihaela
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑您已将 JPA API jar 包含在您的 EAR 中。当使用“parent last”(也称为“首先使用应用程序类加载器加载类”)时,您的应用程序将加载 javax.persistence.spi.PersistenceProvider 类的第二个副本,该副本与 WAS 中包含的副本不兼容。您需要从 EAR 中删除这些类,或者改回“父级优先”委托模式。
I suspect that you've included the JPA API jar in your EAR. When using "parent last" (also known as "load classes with application class loader first"), your application is loading a second copy of the javax.persistence.spi.PersistenceProvider class, which is incompatible with the copy included in WAS. You need to either remove those classes from your EAR or change back to "parent first" delegation mode.