CrudRepository .delete() 方法是事务性的吗?

Is the CrudRepository .delete() method transactional?

使用 Spring 数据时,可以扩展 CrudRepository

这个存储库 .delete() 方法如何工作 "under the hood"?

还有,这个方法是Transactional吗?如果是这样,在使用Spring-data.

时是否需要使用@Transactional注解

例如这里需要@Transactional吗? :

扩展 CrudRepository:

public interface PersonRepository extends CrudRepository<Person, Integer> {

}

在服务中使用删除方法class:

 @Transactional
 public void deletePerson(Person person) {

        personRepository.delete(person);
    }

编辑: @Transactional 在这里如何工作?

 @Transactional
     public void deletePersonAndTable(Person person, Table table) {

            personRepository.delete(person);

            tableRepository.delete(Table);

        }

您不需要自己添加@Transactional 注解。

来自https://spring.io/blog/2011/02/10/getting-started-with-spring-data-jpa/

Additionally, we can get rid of the @Transactional annotation for the method as the CRUD methods of the Spring Data JPA repository implementation are already annotated with @Transactional.

但是你应该在你的 DOA 中添加一个,如果你想连续执行一些应该只一起执行的操作或者 none 根本不执行(这就是交易的目的)。