Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88285f7

Browse files
Fix DELETE query in derived delete operations
- Use correct ID column for child entities in JdbcDeleteQueryCreator - Remove getIdDefiningParentPath() to reference current entity ID - Rename parentIdColumns to idColumns for clarity - Add test case for custom ID column name (@column("CHILD_ID")) Fixes errors when deleting child entities with non-standard ID column names. Fixes #2123
1 parent ca45cd5 commit 88285f7

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

‎spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcDeleteQueryCreator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ private void deleteRelations(RelationalPersistentEntity<?> entity, Select parent
150150

151151
Condition inCondition = Conditions.in(expression, parentSelect);
152152

153-
List<Column> parentIdColumns = aggregatePath.getIdDefiningParentPath().getTableInfo().idColumnInfos()
153+
List<Column> idColumns = aggregatePath.getTableInfo().idColumnInfos()
154154
.toColumnList(table);
155155

156156
Select select = StatementBuilder.select( //
157-
parentIdColumns //
157+
idColumns //
158158
).from(table) //
159159
.where(inCondition) //
160160
.build();

‎spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryWithCollectionsChainHsqlIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.springframework.data.jdbc.testing.EnabledOnDatabase;
1818
import org.springframework.data.jdbc.testing.IntegrationTest;
1919
import org.springframework.data.jdbc.testing.TestConfiguration;
20+
import org.springframework.data.relational.core.mapping.Column;
2021
import org.springframework.data.repository.CrudRepository;
2122
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
2223

@@ -109,7 +110,7 @@ static class ChildElement {
109110

110111
String name;
111112
Set<GrandChildElement> content = new HashSet<>();
112-
@Id private Long id;
113+
@Id@Column("CHILD_ID") private Long id;
113114
}
114115

115116
static class GrandChildElement {

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryWithCollectionsChainHsqlIntegrationTests-hsql.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CREATE TABLE DUMMY_ENTITY
55
);
66
CREATE TABLE CHILD_ELEMENT
77
(
8-
ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
8+
CHILD_ID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1) PRIMARY KEY,
99
NAME VARCHAR(100),
1010
DUMMY_ENTITY BIGINT
1111
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /