marks the start
of a JTA transaction. My question is, what marks the end of the above JTA method transaction. Is there anything in code that marks the end of the JTA
transaction method? How does the container know ?
Originally posted by Marimuthu Madasamy:
Transaction Scoped Persistence context starts and ends within the scope of a business method.
Here the REQUIRED transaction attribute specfies that the method has to be executed in a transaction.
All container managed transaction scoped entity managers depend on JTA transactions. The reason for this is because they can use the transaction as a way to track persistence contexts. Every time an operation is invoked on the entity manager, it checks to see if a persistence context is associated with the transaction.
If it finds one, the entity manager will use this persistence context. If it doesn�t find one, then it creates a new persistence context and associates it with the transaction. When the transaction ends, the persistence context goes away.
The application may obtain a container-managed entity manager with transaction-scoped persistence
context bound to the JTA transaction by injection or direct lookup in the JNDI namespace. The persistence
context type for the entity manager is defaulted or defined as PersistenceContext-
A new persistence context begins when the container-managed entity manager is invoked in the
scope of an active JTA transaction, and there is no current persistence context already associated with
the JTA transaction. The persistence context is created and then associated with the JTA transaction.
The persistence context ends when the associated JTA transaction commits or rolls back, and all entities
that were managed by the EntityManager become detached.
If the entity manager is invoked outside the scope of a transaction, any entities loaded from the database
will immediately become detached at the end of the method call.