File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Persistence Context Propagation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Persistence Context Propagation" Watch "Persistence Context Propagation" New topic
Author

Persistence Context Propagation

Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Hello

Please explain following
If EJB call another EJB with a different transaction scope, the persistence context, whether extended or non extended, is not propagated




Thanks


"Know where to find the solution and how to use it - that's the secret of success."
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Mates any help on above post
Victor Bucutea
Ranch Hand

Joined: Nov 24, 2008
Posts: 43
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.
Victor Bucutea
Ranch Hand

Joined: Nov 24, 2008
Posts: 43

e.g. the stategull bean is removed or passivated

WRONG !


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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persistence Context Propagation