-
Sep 28th, 2010, 10:42 PM
#1
Transaction related question
Hello all,
could be a stupid question:- I have a requirement that part of the same transaction, I need to insert and subsequently make two more updates to the same records (same pk) in a single transaction. These operations have to be all or nothing. Anyway to achieve in a single transaction? or any other idea?
Thanks,
-
Sep 29th, 2010, 01:02 AM
#2
And the problem here is?!
Simply do it... Make a method that spans these actions, make it transactional and presto...
-
Sep 29th, 2010, 05:54 AM
#3
problem is it ignores 2nd and 3rd operations (two updates)
how can below be possible since its atomic? In a transaction its creating an object trying to update() same object (record) two times.
tx.begin(){
Object obj service.createObject();//db save
if(obj !=null){
obj.setDate(new Date());
service.updateObject(); //db update
//some more stuff and call updateObject() again
service.updateObject(); //db update
}
}
tx.end()
-
Sep 29th, 2010, 06:11 AM
#4
Why are you starting a tx yourself (and please use [ code][/code ] tags
).
If it isn't happening, you configured something wrong, also if you are using hibernate there is no need to call an update method (after you persisted/saved) the object, changes are detected automatically.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules