Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

embedding a update & get in a ejb transaction

 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am using a Stateless Session EJB with Container Managed Transaction which in turn uses Hibernate to update & fetch data from databases.

We have a scenario where the user would update a record or insert a new record & then we have to display the updated or inserted record.
So we have methods like updateRecord, insertRecord & getRecord in our SLSB.

The insert & update use transaction & the get does not. Hence once the update & insert are successful they will be committed to the database & the transaction is over.

Now the requirement is that say if the user inserts or updates the record successfully but the subsequent get method fails in fetching the updated/inserted record then the insert/update should also rollback if the get fails.
The client says the user gets a wrong impression that the record did not persist since the get failed.
I.e. we want the update/insert & get both to succeed or if the get fails then even the update/insert should rollback

How can the same be acheived using EJB transactions.


Regards,

Manish
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First are we here talking about the same data thas was updated and inserted . If 'Yes' then the get method needs to be also put in the transaction .
You have to use the same transactions attribute for get as other 2 methods use . This is weird but no way out .

One imp thing u need to take care while doing is ISOLATION . As you want the same record back setting right isloation level is the trick here.
 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nikhil

Thanks for the reply.

I need the same inserted/updated data to be displayed via the get method. I agree with your point to keep the get method also as part of the transaction.
But ideally the insert or update method will complete the transaction when the method ends. So subsequently even if the get fails i do not have control over the transaction which completed the insert or update as it may have already been committed to the database.

I am not that conversant with EJB transactions. I guess since i am using CMT the transaction scope ends at the method level & the get , insert & update would be 3 different transactions


Regards,

Manish
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic