The Container’s responsibilities

  1. If the bean throws an application exception, send it back to the client EXACTLY as it was thrown, and do NOT rollback the transaction.

    If the bean throws a CreateException, send that exception to the client. If the bean throws a FinderException, send that exception to the client. If the bean throws an AccountBalanceException, send that exception to the client.

    It makes no difference whether the exception is one of the standard EJB exceptions from the java.ejb package, or one that the Bean Provider defined.

    image with no caption
  2. If the bean throws a system exception (including EJBException or any runtime exception)

    • Throw a RemoteException if the client is Remote

    • Throw an EJBException if the client is local

    • Log the exception

    • Rollback the transaction

    • Discard the bean instance (assume it’s toast)

    image with no caption

Brain Power

Think about the client for a moment. If the client gets a RemoteException, does the client know for certain that the business method completed?

Does the client know for certain that the transaction was rolled back?

Is there any way the client might be able to find out?

What if the client is another bean?

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.