TomEE 4 JPA 问题

发布于 2024-12-20 07:11:19 字数 807 浏览 4 评论 0原文

我正在 TomEE 4.0.0 上尝试简单的 JPA 示例,但无法让 PersistenceContextType.EXTENDED 工作

如果我使会话 bean 无状态并保留 PersistenceContextType 那么它工作正常

@PersistenceContext(unitName = "xxx" )
private EntityManager entityManager;

如果我将会话 bean 保持为无状态,然后尝试使用这

@PersistenceContext(unitName = "xxx", type = PersistenceContextType.EXTENDED))
private EntityManager entityManager;

在部署时给了我一个错误,这完全没问题并且符合预期。

但是现在当我将我的bean设置为@Stateful时,它也会给我一个错误

Managed ejbs are not capable of using EntityManagers with EXTENTED persistence.  Convert your bean to a Stateful ejb or update the "java:comp/env/com.testwebservice.TestJPAService/entityManager" PersistenceContext reference to PersistenceContextType.TRANSACTION.

有人可以帮忙吗,我对此感到非常困惑

I am trying out simple JPA example on TomEE 4.0.0 and I am not able to get PersistenceContextType.EXTENDED working

If I make my session bean Stateless and leave PersistenceContextType then it works fine

@PersistenceContext(unitName = "xxx" )
private EntityManager entityManager;

If I keep my session bean as Stateless and then try to use this

@PersistenceContext(unitName = "xxx", type = PersistenceContextType.EXTENDED))
private EntityManager entityManager;

it gives me an error while deploying, which is perfectly fine and in line with expectation.

However now when I make my bean as @Stateful, then also it gives me an error

Managed ejbs are not capable of using EntityManagers with EXTENTED persistence.  Convert your bean to a Stateful ejb or update the "java:comp/env/com.testwebservice.TestJPAService/entityManager" PersistenceContext reference to PersistenceContextType.TRANSACTION.

Can some one please help, I am really confused for this

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

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

发布评论

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

评论(1

预谋 2024-12-27 07:11:19

@Stateful 扩展持久化上下文在 TomEE 构建以及 Java EE TCK 中以多种方式进行了测试。

可能这完全是另一回事。当您注意到 @StatelessPersistenceContextType.EXTENDED 的不正确组合时,我们会尽力在您犯下明显错误时发出警告。

查看包含 的 JNDI 名称com.testwebservice.TestJPAService 并考虑到它在更改为 @Stateful 之前是 @Stateless,我的猜测是这个 bean 也是一个@WebService 这是非法的。 @Stateful bean 不能是 @WebService bean。如果没有适当的检查来防止这种错误,我的猜测是该 bean 实际上被部署了两次;一次作为 @Stateful bean,一次作为 pojo @WebService。 pojo Web 服务是导致错误的原因。

如果出现这种错误,我已提交 JIRA 供我们明确检查该条件< /a>.

@Stateful EXTENDED persistence contexts are tested in numerous ways in the TomEE build and also in the Java EE TCK.

Likely this is something else completely. We do our best to warn you when you make obvious mistakes as you note with the incorrect combination of @Stateless with PersistenceContextType.EXTENDED

Looking at the JNDI name which contains com.testwebservice.TestJPAService and given the fact it was @Stateless before it was changed to @Stateful, my guess is that this bean is also an @WebService which is illegal. @Stateful beans cannot be @WebService beans. Without a proper check to prevent this mistake, my guess is that the bean is actually being deployed twice; once as a @Stateful bean and once as an pojo @WebService. The pojo web service is the one causing the error.

In case that is the error, I've filed a JIRA for us to explicitly check that condition.

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