Exceptions

The EJB3 cartridge provides a similar exception handling process for applications as the other persistence cartridges.

Simply model a class and assign it the <<ApplicationException>> stereotype or the <<UnexpectedException>> stereotype (you will need to enable the Java cartridge for this to work).

A default exception will be generated for all services since the allowDefaultServiceException namespace property is set to true by default. A set of default crud exceptions will also be generated and used in manageable service beans for manageable entities. Please refer to Manageable Entities for more information on manageable service exceptions.

EJB3 entities no longer throw exceptions. Following the session facade pattern, all business logic should reside in the session bean, therefore, only the session bean should throw application specific exceptions.

The next thing to do is draw a dependency from a <<Service>> to this exception, this will make all operations throw this exception. You may choose to have a single operation throw a specific exception by drawing the dependency from that operation to the exception.

The following example builds on top of our tutorial example and adds the RentalException application exception which is thrown from all operations of the RentalService related classes. Notice how the bean class, bean implementation class, interface classes and delegate class throw this exception from all operations.

images/org/andromda/test/7/a/uml.gif

  • Auto-generated source that does not need manual editing
  • Auto-generated source that should be edited manually
  • File that is affected by the modifications applied in this section

Next

The next section covers the declarative security handling with JBossSX, click here to go to that section.