Results 1 to 9 of 9

Thread: DAO Templates and Transactions

  1. #1
    Join Date
    Jul 2007
    Posts
    12

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 04:27 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jul 2007
    Posts
    12

    Default

    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?

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 04:26 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #5
    Join Date
    Jul 2007
    Posts
    12

    Default

    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.

  6. #6
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    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.

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 04:26 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 04:26 PM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  9. #9
    Join Date
    Jul 2007
    Posts
    12

    Default

    Quote 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.

Posting Permissions

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