• Post Reply Bookmark Topic Watch Topic
  • New Topic

CMT doesn't commit DB changes in a POJO

 
Jash Rathore
Greenhorn
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.

Thanks
 
Devaka Cooray
Marshal
Posts: 5209
508
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Teddy Westside", please check your private messages regarding an important administrative matter.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!