Win a copy of Fixing your Scrum this week in the Agile 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

modification for chapter 6's persistenceContextCollision

 
Bartender
Posts: 2111
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modified this example:



Our expected result is collision:


javax.ejb.EJBException: There is an active transactional persistence context for the same EntityManagerFactory as the current stateful session bean's extended persistence context

 
Himai Minh
Bartender
Posts: 2111
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To make it work, let the stateful bean starts a new transaction instead of using the propagated transaction:


Reference:http://shengwangi.blogspot.com/2015/11/understand-persistence-context-collision.html
 
Himai Minh
Bartender
Posts: 2111
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason why I suggested this modification because  the original code demonstrated another concept , not pc collision.
The original code tells us that an stateful bean  with container managed transaction  cannot run in a UserTransaction.
The output error message is actually:

javax.ejb.EJBException: java.lang.IllegalStateException: Bean is associated with a different unfinished transaction



Original code as Audit bean is stateless with transaction scoped PC and Department manager bean as stateful with extended PC.






 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic