【发布时间】:2020-02-02 15:22:31
【问题描述】:
此链接:https://www.quora.com/When-should-Spring-Boot-methods-use-the-Transactional-annotation
解释清楚@Transactional在做什么,但是我还是不明白Spring Boot方法什么时候应该使用这个注解:
例如:
我有这个方法:
void addPerson () {// code that calls the DAO layer}
我的方法在没有 @Transactional 注释的情况下也能很好地工作,那么为什么我应该添加这个注释。
更准确地说(在 spring boot 中)有什么区别:
@Transactional void addPerson () {// code that calls the DAO layer}
和
void addPerson () {// code that calls the DAO layer}
或者Spring boot会自动添加这个注解,所以我们不需要将它添加到我们的服务中
【问题讨论】:
标签: hibernate spring-boot jpa transactions spring-data-jpa