Websphere 7 EntityManagerFactory 创建问题

发布于 2024-08-31 14:04:08 字数 1482 浏览 7 评论 0原文

我正在开发一个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:

Any hint will be useful.
Thanks in advance!
Mihaela

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帅的被狗咬 2024-09-07 14:04:08

我怀疑您已将 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文