Java Reference
In-Depth Information
NEVER
In a CMT, NEVER means that the EJB method can never be invoked from a transactional
client. If such an attempt is made, a javax.ejb.EJBException is thrown. This is
probably the least-used transaction attribute value. It's possibly useful if your method is
changing a nontransactional resource (such as a text file) and you want to make sure the cli-
ent knows about the nontransactional nature of the method. Note that you aren't supposed
to directly access the file system from an EJB.
Transaction attributes and MDBs
As discussed in chapter 4 , MDBs don't support all six transaction attributes. MDBs support
only REQUIRED or NOT_SUPPORTED . Remember that no client ever invokes MDB
methods directly—they're invoked when a message is delivered to the bean from the
queue. There's no existing transaction to suspend or join when a message is delivered;
therefore, REQUIRES_NEW , SUPPORTS , and MANDATORY make no sense. NEVER is il-
logical because you don't need a strong guard against the container. The two options you
have available are REQUIRED if you want a transaction or SUPPORTS if you don't need a
transaction.
You now have a handle on how to mark a bean as using CMTs and how to demarcate or
join an existing transaction. The successful conclusion of a transactional method results in
the transaction being committed. Let's next look at how you can mark a transaction for roll-
back.
6.2.4. Marking a CMT for rollback
Sometimes in the course of a transaction it's determined that the changes need to be rolled
back. The rollback could be due to an error, an invalid credit card number, or a result of a
business decision. CMT provides the capability for the bean to signal that the transaction
must be rolled back. The rollback doesn't take place immediately—a flag is set, and at the
end of the transaction the container will perform the rollback. Let's revisit the code from
listing 6.1 to see how this is done:
@Resource
private SessionContext context;
public void placeSnagItOrder(Item item, Bidder bidder, CreditCard card) {
try {
} catch (CreditProcessingException ce) {
Search WWH ::




Custom Search