Announcement Announcement Module
Collapse
No announcement yet.
DAO Templates and Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • DAO Templates and Transactions

    Does Dao Template start a transaction for each operation (load(), save(), get())? if so, do we need a transaction at this dao layer? Don't we start a transaction at service layer?

  • #2
    Which DAO are you working with? If you don't specify transaction in some form then you are presumably going to be relying on autocommit.
    Last edited by karldmoore; Aug 27th, 2007, 05:27 PM.

    Comment


    • #3
      I'm using hibernate template and in application-context.xml i define transaction properties for my services. in "spring in action" book, "consistent dao support" part, it shows that template class also start a transaction.
      is there a duplication?

      Comment


      • #4
        If you are using a transaction at the service layer, everything should participate in that transaction if you are using the thread bound Session, e.g. using HibernateTemplate or SessionFactory.getCurrentSession();
        http://blog.interface21.com/main/200...r-jpatemplate/
        Last edited by karldmoore; Aug 27th, 2007, 05:26 PM.

        Comment


        • #5
          do you mean if there is a transaction at service layer then it is used.
          if there isn't a transaction at service layer then dao templates starts one.

          Comment


          • #6
            If you yourself do not define transactions, there are none. Hibernate template _never_ starts a transaction.

            If you define transactions at service level and dao level what will happen depends on transaction propagation you defined. Usually there is no need to define transactions on dao level.

            Comment


            • #7
              Originally posted by dejanp View Post
              If you define transactions at service level and dao level what will happen depends on transaction propagation you defined. Usually there is no need to define transactions on dao level.
              That's what I was trying to say . The HibernateTransactionManager configured at the service layer will allow the DAO to participate in the transaction and also HibernateTemplate to use the same thread-bound Session.
              http://www.springframework.org/docs/...ansaction.html
              Last edited by karldmoore; Aug 27th, 2007, 05:26 PM.

              Comment


              • #8
                Just to add, I really would have a look at that blog post. If you are starting a new project it might be an idea to leave HibernateTemplate behind.
                Last edited by karldmoore; Aug 27th, 2007, 05:26 PM.

                Comment


                • #9
                  Originally posted by dejanp View Post
                  If you define transactions at service level and dao level what will happen depends on transaction propagation you defined. Usually there is no need to define transactions on dao level.
                  I also think this is the case but I was confused with instructions in the book.
                  Thank you for your replies.

                  Comment

                  Working...
                  X