Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

embedding a update & get in a ejb transaction  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • 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
 
Nikhil Goel
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!