If EJB call another EJB with a different transaction scope, the persistence context, whether extended or non extended, is not propagated
"Know where to find the solution and how to use it - that's the secret of success."
Joined: Nov 14, 2005
Mates any help on above post
Joined: Nov 24, 2008
Persistence context can be EXTENDED or TRANSACTION.
Basically the lifetime of a PersistenceContext is not equivalent to the lifetime of a transaction not . So if we declare a persistence context of type extended those entities from within the PC will remain managed until the PC is removed ( e.g. the stategull bean is removed or passivated).
In a TRANSACTION PC type the lifetime of the PC is until the transaction is commited.
the term is really related to PersistenceContext type and not to transactions. The persistence context is not propagated across calls between components.
here is a detailed explanation from mikalai zaikin's notes :
If a component is called and there is no JTA transaction or the JTA transaction is not propagated, the persistence context is not propagated.
If an entity manager is then invoked from within the component - it does make things more complicated but it's worth understanding:
Invocation of an entity manager defined with PersistenceContextType.TRANSACTION will result in use of a NEW persistence context.
Invocation of an entity manager defined with PersistenceContextType.EXTENDED will result in the use of the existing extended persistence context bound to that component.
If the entity manager is invoked within a JTA transaction, the persistence context will be bound to the JTA transaction.
If a component is called and the JTA transaction is propagated into that component:
If the component is a stateful session bean to which an extended persistence context has been bound and there is a different persistence context bound to the JTA transaction, an EJBException is thrown by the container.
Otherwise, if there is a persistence context bound to the JTA transaction, that persistence context is propagated and used.
Joined: Nov 24, 2008
e.g. the stategull bean is removed or passivated
The Extended PC remains open for the lifetime of the BEAN. It does not get closed when the bean is passivated.It only gets closed when the bean's @Remove annotated method is called.