12
12
import org .springframework .context .annotation .Configuration ;
13
13
import org .springframework .context .annotation .Import ;
14
14
import org .springframework .data .annotation .Id ;
15
+ import org .springframework .data .relational .core .mapping .Column ;
15
16
import org .springframework .data .jdbc .repository .support .JdbcRepositoryFactory ;
16
17
import org .springframework .data .jdbc .testing .DatabaseType ;
17
18
import org .springframework .data .jdbc .testing .EnabledOnDatabase ;
@@ -32,6 +33,7 @@ class JdbcRepositoryWithCollectionsChainHsqlIntegrationTests {
32
33
33
34
@ Autowired NamedParameterJdbcTemplate template ;
34
35
@ Autowired DummyEntityRepository repository ;
36
+ @ Autowired CustomIdDummyEntityRepository customIdRepository ;
35
37
36
38
private static DummyEntity createDummyEntity () {
37
39
@@ -40,6 +42,13 @@ private static DummyEntity createDummyEntity() {
40
42
return entity ;
41
43
}
42
44
45
+ private static CustomIdDummyEntity createCustomIdDummyEntity () {
46
+
47
+ CustomIdDummyEntity entity = new CustomIdDummyEntity ();
48
+ entity .name = "Custom ID Entity Name" ;
49
+ return entity ;
50
+ }
51
+
43
52
@ Test // DATAJDBC-551
44
53
void deleteByName () {
45
54
@@ -60,6 +69,26 @@ void deleteByName() {
60
69
assertThat (count ).isEqualTo (0 );
61
70
}
62
71
72
+ @ Test // DATAJDBC-2123
73
+ void deleteByNameWithCustomIdColumn () {
74
+
75
+ CustomIdChildElement element1 = createCustomIdChildElement ("one" );
76
+ CustomIdChildElement element2 = createCustomIdChildElement ("two" );
77
+
78
+ CustomIdDummyEntity entity = createCustomIdDummyEntity ();
79
+ entity .content .add (element1 );
80
+ entity .content .add (element2 );
81
+
82
+ entity = customIdRepository .save (entity );
83
+
84
+ assertThat (customIdRepository .deleteByName ("Custom ID Entity Name" )).isEqualTo (1 );
85
+
86
+ assertThat (customIdRepository .findById (entity .id )).isEmpty ();
87
+
88
+ Long count = template .queryForObject ("select count(1) from custom_id_grand_child_element" , new HashMap <>(), Long .class );
89
+ assertThat (count ).isEqualTo (0 );
90
+ }
91
+
63
92
private ChildElement createChildElement (String name ) {
64
93
65
94
ChildElement element = new ChildElement ();
@@ -76,10 +105,30 @@ private GrandChildElement createGrandChildElement(String content) {
76
105
return element ;
77
106
}
78
107
108
+ private CustomIdChildElement createCustomIdChildElement (String name ) {
109
+
110
+ CustomIdChildElement element = new CustomIdChildElement ();
111
+ element .name = name ;
112
+ element .content .add (createCustomIdGrandChildElement (name + "1" ));
113
+ element .content .add (createCustomIdGrandChildElement (name + "2" ));
114
+ return element ;
115
+ }
116
+
117
+ private CustomIdGrandChildElement createCustomIdGrandChildElement (String content ) {
118
+
119
+ CustomIdGrandChildElement element = new CustomIdGrandChildElement ();
120
+ element .content = content ;
121
+ return element ;
122
+ }
123
+
79
124
interface DummyEntityRepository extends CrudRepository <DummyEntity , Long > {
80
125
long deleteByName (String name );
81
126
}
82
127
128
+ interface CustomIdDummyEntityRepository extends CrudRepository <CustomIdDummyEntity , Long > {
129
+ long deleteByName (String name );
130
+ }
131
+
83
132
@ Configuration
84
133
@ Import (TestConfiguration .class )
85
134
static class Config {
@@ -95,6 +144,11 @@ Class<?> testClass() {
95
144
DummyEntityRepository dummyEntityRepository () {
96
145
return factory .getRepository (DummyEntityRepository .class );
97
146
}
147
+
148
+ @ Bean
149
+ CustomIdDummyEntityRepository customIdDummyEntityRepository () {
150
+ return factory .getRepository (CustomIdDummyEntityRepository .class );
151
+ }
98
152
}
99
153
100
154
static class DummyEntity {
@@ -118,4 +172,24 @@ static class GrandChildElement {
118
172
@ Id private Long id ;
119
173
}
120
174
175
+ static class CustomIdDummyEntity {
176
+
177
+ String name ;
178
+ Set <CustomIdChildElement > content = new HashSet <>();
179
+ @ Id private Long id ;
180
+ }
181
+
182
+ static class CustomIdChildElement {
183
+
184
+ String name ;
185
+ Set <CustomIdGrandChildElement > content = new HashSet <>();
186
+ @ Id @ Column ("CHILD_ID" ) private Long id ;
187
+ }
188
+
189
+ static class CustomIdGrandChildElement {
190
+
191
+ String content ;
192
+ @ Id private Long id ;
193
+ }
194
+
121
195
}
0 commit comments