O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Burn these in

These are all things you might be tested on. But remember, you won’t be asked a simple true or false question, like, “The getRollbackOnly() method can be called from a method with a transaction attribute of NotSupported.” (In which case the answer would be false, of course). No, you’re likely to see something much more clever, like bean code plus the bean’s deployment descriptor, and you have to decide if it all works together.

Note

getRollbackOnly() MUST be called from a bean in a transaction!

You already know that getRollbackOnly() can be called only by CMT beans, and that the method exists only in EJBContext and NOT in UserTransaction. (Remember? BMT beans can call getStatus() on UserTransaction, but they can’t call getRollbackOnly().)

But for getRollbackOnly() to work, the method must be in a transaction, which means you MUST use only:

* Requires

* RequiresNew

* Mandatory

Note

Message-driven beans can use only TWO attributes: Requires and NotSupported.

Think about it. A message-driven bean doesn’t have a calling client! The container calls the onMessage() method, so it doesn’t make any sense to use the other ones. RequiresNew? That’s useless because there will never be a pre-existing transaction. Mandatory? That would blow up every time (by “blow up” we mean throw an exception) because Mandatory means “Requires Pre-Existing”. Never? Well, that is always the case anyway, and Supports is silly too. You can say only two things for onMessage():

YES, I want to start a transaction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required