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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access