Special Edition Using Enterprise JavaBeans 2.0
Troubleshooting
Transaction Attributes Not Specified
I get errors at deployment related to the assignment of transaction attributes. When you're using container-managed transaction demarcation , you must include trans-attribute entries in the deployment descriptor for a bean that, as a group , applies to all its business methods . You're also restricted in the attributes that can be assigned based on the type of EJB you're deploying. Remember as well that the trans-attribute element is only valid when you've defined the transaction-type for the bean to be Container . TransactionRequiredException
I get a TransactionRequiredException (or TransactionRequiredLocalException ) when I call a bean method. This exception is used when a method is deployed with a transaction attribute of Mandatory and no client transaction exists when the method is called. You should first convince yourself that Mandatory is the appropriate attribute for the method because its use isn't typical. If it is valid, you need to start a transaction using a UserTransaction before calling the method. Exception Using setRollbackOnly
I get an exception when I call setRollbackOnly . The important rule about calling setRollbackOnly is to call it on the correct object. If you're using container-managed demarcation, you have to call this method on EJBContext to mark a transaction for rollback. If you're instead using bean-managed demarcation, you have to call this method on the associated UserTransaction to achieve the same result. Accessing the incorrect object results in an IllegalStateException . Transaction Not Rolled Back After an Exception
The results of an in-progress transaction are not rolled back when an exception is thrown. The handling of exceptions is closely tied to transactions and you're responsible for reacting to exceptions in a certain way to manage a transaction correctly when an error occurs. Refer to the "Exceptions and Transactions" section in Chapter 13 for detailed coverage on this subject. |