Best Practices

Bean-managed transaction demarcation is only used by more advanced users who want more control over the application workflow. The J2EE architecture recommends managing transactions through container-managed demarcation. Declarative transaction management provides one of the major benefits of the J2EE platform, by freeing the EJB developer from the burden of managing transactions.

Use JTA, where possible, in managing transaction boundaries in enterprise applications. This guarantees data consistency and integrity, and ensures that work performed by multiple components through multiple resource managers is grouped as an atomic unit.

Only session beans and message-driven beans can use both bean-managed transaction and container-managed transaction demarcation. Entity beans must use only container-managed demarcation.

An EJB should not invoke resource manager-specific transition demarcation API methods, such as commit() and rollback() of the Connection interface, within a transaction. It uses only the methods of the UserTransaction interface to manage transaction boundaries.

Stateless session beans should always either commit or roll back a transaction before the business method returns. Stateful session beans do not have this requirement. EJBs with BMT should not invoke the getRollbackOnly() and setRollbackOnly() methods of the EJBContext interface. These methods should be used only in container-managed transactions. For bean-managed transactions, you should invoke the getStatus() and rollback() methods of the UserTransaction interface.

Servlets and JSP are used in nontransactional tasks, such as data presentation and user interaction. Because transactions tend to be associated with business logic, database access and other transactional work should be handled by a transactional EJB.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.75.221