views:

178

answers:

4

Could you explain, what happens behind the scene?

Transaction management when using this template in Spring is absolutely unclear.

What if I invoke 10 DAO methods that all use the same Hibernatetemplate and I invoke them one after another? Every method runs within its own transaction?

It's not effective is not it?

+2  A: 

In general you would put your transactions on your service layer see the Spring docs.

HeDinges
+2  A: 

If you are just using the hibernate template then the out of the box behaviour is to autocommit everything your daos do. You need a transaction manager to look after your this behaviour. Transactions are sort of orthogonal to the hibernate template.

mR_fr0g
A: 

You should be using Spring declarative transaction management on services, not DAOs.

Services know about units of work, not DAOs.

duffymo
A: 

The transactions are defined in services, you want to avoid defining transactions in DAO's DAO layer with perform the data operations within the transactions defined at the service layer.

ravi