Skip to content

Commit

Permalink
Merge pull request #42376 from famod/fix-spring-flushAutomatically
Browse files Browse the repository at this point in the history
Fix spring-data-jpa `@Modifying(flushAutomatically = true)`
  • Loading branch information
gsmet authored Aug 7, 2024
2 parents 5b7ef46 + 296b43e commit a34e10f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ModifyingQueryWithFlushAndClearTest {
public void setUp() {
final User user = getUser("JOHN");
user.setLoginCounter(0);
user.getLoginEvents().clear();
repo.save(user);
}

Expand Down Expand Up @@ -69,8 +70,9 @@ public void testNoAutoFlush() {

final User verifyUser = getUser("JOHN");
// processLoginEvents did not see the new login event
assertThat(verifyUser.getLoginEvents()).hasSize(1);
final boolean allProcessed = verifyUser.getLoginEvents().stream()
.allMatch(loginEvent -> loginEvent.isProcessed());
.allMatch(LoginEvent::isProcessed);
assertThat(allProcessed).describedAs("all LoginEvents are marked as processed").isFalse();
}

Expand All @@ -83,8 +85,9 @@ public void testAutoFlush() {
repo.processLoginEventsPlainAutoClearAndFlush();

final User verifyUser = getUser("JOHN");
assertThat(verifyUser.getLoginEvents()).hasSize(1);
final boolean allProcessed = verifyUser.getLoginEvents().stream()
.allMatch(loginEvent -> loginEvent.isProcessed());
.allMatch(LoginEvent::isProcessed);
assertThat(allProcessed).describedAs("all LoginEvents are marked as processed").isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public static void clear(Class<?> clazz) {
}

public static void flush(Class<?> clazz) {
Panache.getSession(clazz).clear();
Panache.getSession(clazz).flush();
}
}

0 comments on commit a34e10f

Please sign in to comment.