This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

CMT doesn't commit DB changes in a POJO

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the code flow : Session Bean --> Pojo( working on JPA entities) --> DB.
As the POJO class is doing the JPA writes, I have configured it to resource_local and using entitymanagerFactory to get entitymanager and entitymanager.gettransaction to begin and commit transactions.
In one of the scenarios, the Session bean calls one of the methods of the Pojo where it has to remove some entities. Bean's method is already in a container managed transaction so, if I try to begin or commit the entitymanager.gettransaction in Pojo's method it throws exception. Fair enough as I am not allowed to call commit in a CMT but if I do not use the entitymanager.gettransaction, the JPA updations don't reflect in DB when the CMT is commited.

Update: I assume the reason CMT is not updating the DB is because we close the entityManager before getting out of the method in the POJO. I tried annotating the method with TransactionAttributeType.NOT_SUPPORTED so that I can use entityManager.getTransaction inside but it still behaves like it's still getting called in the CMT.

Any Insight would be really appreciated.

Posts: 6617
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Teddy Westside", please check your private messages regarding an important administrative matter.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic