O'Reilly logo

Java Data Objects by Craig Russell, David Jordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required