If I throw a custom ApplicationException from a business method in Entity bean which is participating in a transaction, would the transaction be rolled back by container?
EJB Transaction is automatically rolled back only when a SystemException (or a subtype of it) is thrown. Your ApplicationExceptions can extend from javax.ejb.EJBException, which is a sub class of RuntimeException. When a EJBException is encountered the container rolls back the transaction. EJB Specification does not mention anything about Application exceptions being sub-classes of EJBException. You can tell container to rollback the transaction, by using setRollBackOnly on SessionContext/EJBContext object as per type of bean you are using.
Related Questions
- If my session bean with single method insert record into 2 entity beans, how can know that the process is done in same transaction (the attributes for these beans are Required)?
- The EJB specification says that we cannot use Bean Managed Transaction in Entity Beans. Why?
- Why does a small business need a custom business sign with a corporate look?