File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persistence Context Propagation

 
Amirr Rafique
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Amirr Rafique
Ranch Hand
Posts: 324
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mates any help on above post
 
Victor Bucutea
Ranch Hand
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic