Scenario Summary
Transaction Scenarios
A CMT bean calls context.getUserTransaction().
The bean gets an IllegalStateException. (Only BMT beans can get a UserTransaction)
Client calls remove() on a stateful bean that is still in an open transaction.
The client gets a RemoveException. You can’t remove a stateful bean while its in a transaction. (Which is just one of a gazillion reasons why it’s a Bad Idea to leave a transaction open across multiple client invocations. In other words, if you begin a BMT transaction in a method, you should end it in that method!)
A CMT bean calls getRollbackOnly(), from a method marked NotSupported.
The bean gets an IllegalStateException. You must be in a transaction when you call getRollbackOnly() or setRollbackOnly(). That means you can’t call them within a method marked NotSupported, Never, or Supports (session and entity beans) or NotSupported (message-driven beans—remember, message-driven beans can’t use Never or Supports, because they don’t make sense given that transactions can never propagate into a message-driven bean.)
Client calls a method on a Remote CMT bean, and the method is marked Mandatory. The caller does not have a transaction context in place when the call comes in.
The client gets a TransactionRequiredException (a local client would get TransactionRequiredLocalException).
A session bean wants the Container to know that the transaction should be rolled back and the bean should be killed.
The bean should throw an EJBException. The Container ...
Get Head First EJB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.