Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JTA Transaction on Stateful Session Bean.

 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From WhizLabs, Diagnostic Exam, Question 39

WhizLabs wrote:If a JTA transaction is propagated into the stateful session bean to which an extended persistence context is bound but with the JTA bound persistence context is different, container throws an EJBException

.

Is this correct? I actually couldn't understand this.
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is correct. Here's why: suppose the SFSB has an extended persistent context, and then another transaction is started elsewhere, and a persistent context is bound to it, and eventually the call is made to the SFSB. Now, if the transaction is propagated to the SFSB (it might not be, if the SFSB method is TransactionAttributeType.NOT_SUPPORTED for example), there are 2 persistence contexts available - the original, extended context, and the new one, propagated with the transaction. There is a clash. Which one should the persistence provider pick and use? It is a hard decision, that hard to throw an exception, actually ;-)
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raf,

Sorry but I couldn't understand this. How it is possible to have two persistence context available at the same time? Shouldn't there be a single persistence context for every transactions?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there should be only one, but you have only one context for a transaction, and the second is the extended context that the SFSB had before, and which is bound to the lifecycle of the bean. So, there would effectivaly be 2 contexts.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I did to understand this.







The client calls to the firstMethod() of the FirstServiceBean. But I didn't get an exception here.


 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's probably because you are not invoking the entity manager in the first bean - the context is simply not created, as JTA contexts are created when first call to an EntityManager is made.

Specs 5.6.1:


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.



So, this would imply that you are propagating the transaction, but as no persistent context was created, it is not propagated.
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh Thanks Raf, I managed to get the EJBException.
Hay, how do you memorized all of the concepts in EJB specs and JPA specs?
 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I studied ;-) And wrote code, and studied some more.
And I do make mistakes, you know that already.
 
    Bookmark Topic Watch Topic
  • New Topic