简体   繁体   中英

Container-managed transaction in JAX-WS, weblogic

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!

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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