Announcement Announcement Module
Collapse
No announcement yet.
Transaction related question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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,

  • #2
    And the problem here is?!

    Simply do it... Make a method that spans these actions, make it transactional and presto...

    Comment


    • #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()

      Comment


      • #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.

        Comment

        Working...
        X