Konstantin Kudryavtsev
Konstantin Kudryavtsev

Reputation: 592

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!

Upvotes: 3

Views: 3181

Answers (1)

maximdim
maximdim

Reputation: 8169

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?

Upvotes: 1

Related Questions