Skip to content

Commit be278ff

Browse files
committed
GH-3990: Add EclipseLink regression test for deleteAllByIdInBatch with simple id.
- Save 3 users and flush to allocate IDs. - Delete two using deleteAllByIdInBatch. - Assert the remaining entity is the expected one. Closes #3990 Signed-off-by: Minho Park <[email protected]>
1 parent f13eaf5 commit be278ff

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public abstract class QueryUtils {
9494

9595
public static final String COUNT_QUERY_STRING = "select count(%s) from %s x";
9696
public static final String DELETE_ALL_QUERY_STRING = "delete from %s x";
97-
public static final String DELETE_ALL_QUERY_BY_ID_STRING = "delete from %s x where %s in :ids";
97+
public static final String DELETE_ALL_QUERY_BY_ID_STRING = "delete from %s x where x.%s in :ids";
9898

9999
// Used Regex/Unicode categories (see https://www.unicode.org/reports/tr18/#General_Category_Property):
100100
// Z Separator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2008-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.jpa.repository.support;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import jakarta.persistence.EntityManager;
21+
import jakarta.persistence.PersistenceContext;
22+
import java.util.List;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
import org.springframework.data.jpa.domain.sample.User;
27+
import org.springframework.data.jpa.repository.JpaRepository;
28+
import org.springframework.test.context.ContextConfiguration;
29+
import org.springframework.test.context.junit.jupiter.SpringExtension;
30+
import org.springframework.transaction.annotation.Transactional;
31+
32+
@ExtendWith(SpringExtension.class)
33+
@ContextConfiguration({"classpath:infrastructure.xml", "classpath:eclipselink-h2.xml"})
34+
@Transactional
35+
class EclipseLinkDeleteAllByIdInBatchSimpleIdTests {
36+
37+
@PersistenceContext
38+
EntityManager em;
39+
40+
private JpaRepository<User, Integer> users;
41+
42+
@BeforeEach
43+
void setUp() {
44+
users = new JpaRepositoryFactory(em).getRepository(UserRepository.class);
45+
}
46+
47+
@Test // GH-3990
48+
void deleteAllByIdInBatchShouldWorkOnEclipseLinkWithSimpleId() {
49+
User one = new User("one", "eins", "[email protected]");
50+
User two = new User("two", "zwei", "[email protected]");
51+
User three = new User("three", "drei", "[email protected]");
52+
53+
users.saveAll(List.of(one, two, three));
54+
users.flush();
55+
56+
users.deleteAllByIdInBatch(List.of(one.getId(), three.getId()));
57+
58+
assertThat(users.findAll()).containsExactly(two);
59+
}
60+
61+
private interface UserRepository extends JpaRepository<User, Integer> {
62+
}
63+
}

0 commit comments

Comments
 (0)