Java Reference
In-Depth Information
REQUIRED
REQUIRED is the default and most commonly applicable transaction attribute value. This
value specifies that the EJB method must always be invoked within a transaction. If the
method is invoked from a nontransactional client, the container will start a transaction be-
fore the method is called and finish it when the method completes. On the other hand, if
the caller invokes the method from a transactional context, the method will join the exist-
ing transaction. In case of transactions propagated from the client, if your method indicates
that the transaction should be rolled back, the container will not only roll back the whole
transaction but will also throw a javax.transaction.RollbackException back
to the client. This lets the client know that the transaction it started has been rolled back
by another method. Your placeSnagItOrder method is invoked from the nontransac-
tional web tier. Therefore, the REQUIRED value in the @TransactionAttribute an-
notation will cause the container to create a new transaction for you. If all the other session
bean methods you invoke from your bean are also marked REQUIRED , when you invoke
them they'll join the transaction created for you. This is fine for your problem because you
want the entire ordering action to be covered by one “umbrella” transaction. In general, you
should use the REQUIRED value if you're modifying any data in your EJB method and you
aren't sure whether the client will start a new transaction before calling your method.
REQUIRES_NEW
The REQUIRES_NEW value indicates that the container must always create a new trans-
action to invoke the EJB method. If the client already has a transaction, it's temporarily
suspended until your method returns. This means that the success or failure of your new
transaction has no effect on the existing client transaction.
From the client's perspective,
1 . Its transaction is paused.
2 . The method is invoked.
3 . The method either commits or rolls back its own transaction.
4 . The client's transaction is resumed as soon as the method returns.
Search WWH ::




Custom Search