Announcement Announcement Module
Collapse
No announcement yet.
Need same transaction for two methods Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need same transaction for two methods

    Hai all


    In my interfacedao call i am having two methods
    saveMaster()--Saves the masterpage
    saveDetail()---saves the detailpage


    I need to give the transaction to this methods,THe problem is both the methods should have the same transaction(i,e) if method saveDetail throws Exception the data saved in saveMaster() should aslo get rollback.

    How to do this.Can anyone guide me pls.

    Have a nice weekend
    Aniesh U.K

  • #2
    You simply create a saveMasterAndDetail() method for which you register the transaction, then in that method you call saveMaster() and saveDetail().

    Bob

    Comment


    • #3
      I generally don't put transactions around my dao methods. I have a service layer who's purpose is to combine dao methods to make up use case related methods. These service layer methods are then marked as transactional (and secured if needed).

      Jonny

      Comment


      • #4
        Originally posted by jwray
        I generally don't put transactions around my dao methods. I have a service layer who's purpose is to combine dao methods to make up use case related methods. These service layer methods are then marked as transactional (and secured if needed).

        Jonny
        Same here. That's what I meant. I guess I wasn't explicit enough.

        Bob

        Comment


        • #5
          hai guys
          Thanks a lot.I really can't understand the service layer.Just give me some hints.my saveMaster is a different class and saveDetail is in different class.I think these should be in same class.Pls correct me if i am wrong.

          Thanks a lot

          happy christmas and new year
          Aniesh U.K
          Last edited by anieshuk; Dec 5th, 2005, 02:01 AM.

          Comment


          • #6
            Originally posted by anieshuk
            hai guys
            Thanks a lot.I really can't understand the service layer.Just give me some hints.my saveMaster is a different class and saveDetail is in different class.I think these should be in same class.Pls correct me if i am wrong.

            Thanks a lot

            happy christmas and new year
            Aniesh U.K
            I think what the replies try to say is instead of applying a transaction directly to the saveMaster and saveDetail-methods, you should create another class that wraps the calls to the two methods and apply the transaction to that method.

            Code:
            TransactionalObject.java:
            
            @Transactional
            public void saveMasterAndDetail(MasterAndDetail bean){
                saveMaster.save(bean);
                saveDetail.save(bean);
            }
            This would allow you to apply the same transaction to both methods easily. If using declarative transaction declaration, the class you'd define with a transaction is the wrapping class's method (TransactionalDao's saveMasterAndDetail-method).

            I hope this clears it up

            Comment


            • #7
              Hai,
              Thanks for u r kind reply.I will try this out and clear my doubt.

              Thanks a lot.


              Happy new Year
              Aniesh U.K

              Comment

              Working...
              X