CAUTION!
@Modifying(clearAutomatically=true)
. :
, . EntityManager , (. JavaDoc EntityManager.clear() ), EntityManager. , EntityManager , @Modifying clearAutomatics true.
, Spring Boot 2.0.4.RELEASE
Spring Data flushAutomatically
(https://jira.spring.io/browse/DATAJPA-806) https://docs.spring.io/spring-data/jpa/docs/2.0.4.RELEASE/api/org/springframework/data/jpa/repository/Modifying.html#flushAutomatically
@Modifying
:
@Modifying(clearAutomatically=true, flushAutomatically=true)
, ?
:
repo {
@Modifying
@Query("delete User u where u.active=0")
public void deleteInActiveUsers();
}
1, flushAutomatically
service {
User johnUser = userRepo.findById(1);
johnUser.setActive(false);
repo.deleteInActiveUsers();
}
2, clearAutomatically
, johnUser.active
service {
User johnUser = userRepo.findById(1);
repo.deleteInActiveUsers();
System.out.println(userRepo.findById(1).isPresent())
System.out.println(userRepo.count())
}
- - , @Modifying
clearAutomatically
& flushAutomatically
, ,