Spring HibernateTemplate: how it deals with transactions?
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 transact开发者_开发技巧ion?
It's not effective is not it?
In general you would put your transactions on your service layer see the Spring docs.
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.
You should be using Spring declarative transaction management on services, not DAOs.
Services know about units of work, not DAOs.
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.
精彩评论