简体   繁体   English

将Hibernate和Spring结合使用时,事务管理的最佳实践是什么?

[英]What is the best practice for transaction management when using Hibernate and Spring together?

As best practice, when using hibernate and spring together which transaction management should I use, Spring's transaction management or Hibernate's transaction management? 作为最佳实践,在使用hibernate和spring时,我应该使用哪些事务管理,Spring的事务管理还是Hibernate的事务管理? I understand that both provides transaction management but since they are usually used together I dont know which to use. 我知道两者都提供了事务管理,但由于它们通常一起使用,所以我不知道使用哪种。 Does it depend on the situation or type of transaction to be handled or is there a rule of thumb when using these frameworks together? 它是否取决于要处理的事务的情况或类型,或者在一起使用这些框架时是否有经验法则?

Spring is supposed to help you use Hibernate's transaction management - it's additional level of abstraction that simply works:) It is much more convenient marking which parts should be transactional (therefore handled by Spring). Spring应该可以帮助你使用Hibernate的事务管理 - 它只是工作的附加抽象级别:)标记哪些部分应该是事务性的(因此由Spring处理)更方便。

Edit: Oh I almost forgot. 编辑:哦,我差点忘了。 With Spring's transactional support you will write LESS code ;) 使用Spring的事务支持,您将编写LESS代码;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM