有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring持久性数据总是在@Modifying注释中刷新,而没有属性“FlusAutomatically=true”

我的服务:

@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);

从官方文件

flushAutomatically: Defines whether we should flush the underlying persistence context before executing the modifying query.

我理解当设置FlushaAutomatically=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

我的代码有什么问题


共 (0) 个答案