Scenarios: what do you think happens?

Technically, this section is like a big stealth Sharpen Your Pencil exercise. Only we just told you, so maybe not so stealthy. Sure, we could just tell you everything one fact after another... but you’ll have a much better chance at remembering it if you work it out for yourself. We summarize everything near the end of the chapter, but do NOT jump there now! Even if you’re someone who never does the exercises, do this scenario walk-through. You’ll think of us fondly when you’re holding your lovely lapel pin that you get from passing the certification exam.

  1. A message-driven bean’s onMessage() method catches an application exception. Can it re-throw the application exception to the Container?

    (Hint: what does a Container usually do when it gets an application exception from a bean? Would the Container be able to do that in this scenario?)

  2. A session bean using CMT has a method marked with the NotSupported transaction attribute. While the method is running, the bean calls setRollbackOnly() on its context. Will this cause an exception? What kind?

    (Hint: think about what setRollbackOnly() does, and what state the bean has to be in.)

  3. A message-driven bean, in the onMessage() method, calls getCallerPrincipal(). What happens?

    (Hint: what’s getCallerPrincipal() used for? Does that make sense here?)

  4. A session bean using CMT has a method marked with the Mandatory transaction attribute. The client calling the method is not in a transaction. What happens?

    (Hint: ...

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.