JAX-WS、weblogic 中容器管理的事务

发布于 2024-12-21 03:19:53 字数 558 浏览 3 评论 0原文

我正在尝试在 Web 服务内使用容器管理的事务,但未创建事务。我有类似的事情:

@WebService(...)
@Stateless
@TransactionManagment(TransactionManagmentType.CONTAINER)
public class ExampleService {

  // EntityManager and other fields

  @TransactionAttribure(TransactionAttributeType.REQUIRED)
  public void test(String s){
     // persist something with EntityManager
  }
}

当我调用此方法时,我得到 javax.persistence.TransactionRequiredException: The method public abstract void javax.persistence.EntityManager.persist(java.lang.Object) 必须在事务上下文中调用。

我做错了什么? 谢谢!

I'm trying to use Container-Managed Transactions inside webservice, but transaction isn't created. I have something like that:

@WebService(...)
@Stateless
@TransactionManagment(TransactionManagmentType.CONTAINER)
public class ExampleService {

  // EntityManager and other fields

  @TransactionAttribure(TransactionAttributeType.REQUIRED)
  public void test(String s){
     // persist something with EntityManager
  }
}

When I call this method, I get javax.persistence.TransactionRequiredException: The method public abstract void javax.persistence.EntityManager.persist(java.lang.Object) must be called in the context of a transaction.

What am I doing wrong?
Thanks!

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

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

发布评论

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

评论(1

对你的占有欲 2024-12-28 03:19:54

据我回忆,“TransactionAttributeType.REQUIRED”意味着仅当当前线程的事务已经在进行时才应调用该方法(换句话说,“在事务上下文中调用”)。目前尚不清楚是否有人在您的案件中开始交易。如果没有人,那么你得到的例外就很有意义了。

现在我不确定如何或当前是否可能跨 Web 服务调用传播事务。即使可能的话,我认为这样做也不是特别好主意。

也许您在您的情况下需要 TransactionAttributeType.REQURES_NEW 以便容器在将控制权传递给带注释的方法之前启动事务?

From what I recall 'TransactionAttributeType.REQUIRED' means that method should be only called when transaction is already in progress for current thread (in other words 'called in context of transaction'). It's not clear who if anybody starts transaction in your case. If nobody then the exception you're getting makes perfect sense.

Now I'm not sure how or is it even currently possible to propagate transaction across Web services call. I don't think this is particularly good idea to do so even if possible.

Perhaps you what you need TransactionAttributeType.REQURES_NEW in your case so Container would start the transaction before passing control to your annotated method?

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