spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.98k stars 1.41k forks source link

Add convenient method `JpaRepository::clear` as companion of `flush` #3471

Closed quaff closed 4 months ago

quaff commented 4 months ago

Sometimes we need to clear persistence context, especially for writing unit tests. We need to inject EntityManager before this commit, it is a bit inconvenient.

mp911de commented 4 months ago

We do not want to mirror EntityManager API on the repository. Exposing the flush method already clutters the repository API and we do not want to continue in that way. We suggest implementing a repository fragment for your convenience.