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?
Printable View
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?
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.
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?
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/
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.
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.
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
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.