Results 1 to 4 of 4

Thread: Transaction related question

  1. #1
    Join Date
    May 2006
    Posts
    111

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    And the problem here is?!

    Simply do it... Make a method that spans these actions, make it transactional and presto...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    May 2006
    Posts
    111

    Post

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •