spring持久性数据总是在@modifying注解中刷新,而没有属性“FlusAutomatically=true”

kq0g1dla  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(200)

我的服务:

@Transactional    
public void get() {
        Long id = 1L;
        TestEntity entity = testRepository.findById(id).orElse(null);
        if (entity == null) return;
        Integer newAge = 2;
        entity.setAge(newAge);
        testRepository.deleteByAge(newAge);
    }

我的存储库

@Modifying(flushAutomatically = false)
@Query("delete from TestEntity  where age = :age")
void deleteByAge(@Param("age") Integer age);

从官方文件
FlusAutomatically:定义在执行修改查询之前是否应刷新底层持久性上下文。
我理解当设置FlusAutomatically=false时。在修改之前,不会执行基础持久性上下文。
但它已经执行了,请查看我的数据库日志。

210704  8:24:21   160 Query set autocommit=0
          160 Query select testentity0_.id as id1_0_0_, testentity0_.age as age2_0_0_, testentity0_.name as name3_0_0_ from tests testentity0_ where testentity0_.id=1
          160 Query update tests set age=2, name='init name' where id=1
          160 Query delete from tests  where age = 2
          160 Query COMMIT
          160 Query set autocommit=1

我看到日志在执行修改查询之前证明了底层持久性上下文

160 Query update tests set age=2, name='init name' where id=1

我的代码有什么问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题