Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
* @author Ernst-Jan van der Laan
* @author Diego Krupitza
* @author Seol-JY
* @author SangMin Lee
*/
@Repository
@Transactional(readOnly = true)
Expand Down Expand Up @@ -237,6 +238,15 @@ public void deleteAllByIdInBatch(Iterable<ID> ids) {
deleteAllInBatch(entities);
} else {

ids.forEach(id -> {
T entity = entityManager.find(entityInformation.getJavaType(), id);
if (entity != null) {
entityManager.remove(entity);
}
});

entityManager.clear();

String queryString = String.format(DELETE_ALL_QUERY_BY_ID_STRING, entityInformation.getEntityName(),
entityInformation.getIdAttribute().getName());

Expand Down Expand Up @@ -275,6 +285,14 @@ public void deleteAllInBatch(Iterable<T> entities) {
return;
}

for (T entity : entities) {
if (entityManager.contains(entity)) {
entityManager.remove(entity);
}
}

entityManager.clear();

applyAndBind(getQueryString(DELETE_ALL_QUERY_STRING, entityInformation.getEntityName()), entities, entityManager)
.executeUpdate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
* @author Geoffrey Deremetz
* @author Krzysztof Krason
* @author Yanming Zhou
* @author SangMin Lee
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("classpath:application-context.xml")
Expand Down Expand Up @@ -3416,6 +3417,35 @@ void mergeWithNativeStatement() {
.map(User::getAge).contains(30);
}

@Test // GH-3360
void removeWhenDeleteAllInBatchWithEntities() {

flushTestUsers();
List<User> userList = repository.findAll();

repository.deleteAllInBatch(userList);

userList.forEach(user ->
assertThat(em.contains(user)).isFalse()
);

}

@Test // GH-3360
void removeWhenDeleteAllByIdInBatch() {

flushTestUsers();
List<User> userList = repository.findAll();
List<Integer> userIds = userList.stream().map(User::getId).toList();

repository.deleteAllByIdInBatch(userIds);

userList.forEach(user ->
assertThat(em.contains(user)).isFalse()
);

}

private Page<User> executeSpecWithSort(Sort sort) {

flushTestUsers();
Expand Down