Best Practices

We always recommend using JTA's UserTransaction context in accessing enterprise data. This will ensure both data consistency and data integrity when multiple components are accessing the same data. If the resource adapter doesn't support JTA, local transactions are recommended for accessing enterprise data.

Container-managed transactions are more optimized because they are handled by the container. They are also easier to manage and deploy because transaction attributes are set in the deployment descriptor. The default transaction attribute should be Required. Using this attribute ensures that the methods of an enterprise bean are invoked under a JTA distributed transaction.

Get Sams Teach Yourself EJB in 21 Days 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.