简体   繁体   English

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

[英]Container-managed transaction in JAX-WS, weblogic

I'm trying to use Container-Managed Transactions inside webservice, but transaction isn't created. 我正在尝试在webservice中使用容器管理的事务,但是没有创建事务。 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. 当我调用此方法时,我得到javax.persistence.TransactionRequiredException:必须在事务的上下文中调用方法public abstract void javax.persistence.EntityManager.persist(java.lang.Object)。

What am I doing wrong? 我究竟做错了什么? Thanks! 谢谢!

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'). 我记得'TransactionAttributeType.REQUIRED'意味着只有在当前线程的事务正在进行时(换句话说'在事务的上下文中调用')才应该调用该方法。 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. 现在我不确定当前是否可以通过Web服务调用传播事务。 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? 也许你在你的情况下需要TransactionAttributeType.REQURES_NEW,所以Container在将控制传递给你带注释的方法之前启动事务?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM