Bean-Managed Transactions

Bean-managed transactions offer the stateless session bean developer additional flexibility, but at the cost of additional complexity.

There are two alternate techniques for demarcating transaction boundaries in your bean code: use the server’s javax.transaction.UserTransaction or use the PersistenceManager’s javax.jdo.Transaction. If you use UserTransaction, you can begin and complete distributed transactions managed by the server’s TransactionManager. If you use JDO’s Transaction, you begin and complete local transactions that are managed completely by the JDO implementation, without any help (or interference) from the container.

javax.transaction.UserTransaction

To use UserTransaction , you obtain it via getUserTransaction( ) from the SessionContext instance, begin the transaction, and then obtain the PersistenceManager from the PersistenceManagerFactory. During getPersistenceManager( ), the PersistenceManagerFactory will automatically associate the PersistenceManager with the active UserTransaction.

When your bean invokes methods of beans that use container-managed transactions, the container automatically associates transactional resources used by the other beans in the current UserTransaction. The transactional resources can be JDO PersistenceManagers, JDBC Connections, or connector resources.

If you require nontransactional access to JDO, you must obtain the PersistenceManager when the UserTransaction is not active. After beginning a UserTransaction ...

Get Java Data Objects 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.