1212import org .springframework .context .annotation .Configuration ;
1313import org .springframework .context .annotation .Import ;
1414import org .springframework .data .annotation .Id ;
15+ import org .springframework .data .relational .core .mapping .Column ;
1516import org .springframework .data .jdbc .repository .support .JdbcRepositoryFactory ;
1617import org .springframework .data .jdbc .testing .DatabaseType ;
1718import org .springframework .data .jdbc .testing .EnabledOnDatabase ;
@@ -32,6 +33,7 @@ class JdbcRepositoryWithCollectionsChainHsqlIntegrationTests {
3233
3334 @ Autowired NamedParameterJdbcTemplate template ;
3435 @ Autowired DummyEntityRepository repository ;
36+ @ Autowired CustomIdDummyEntityRepository customIdRepository ;
3537
3638 private static DummyEntity createDummyEntity () {
3739
@@ -40,6 +42,13 @@ private static DummyEntity createDummyEntity() {
4042 return entity ;
4143 }
4244
45+ private static CustomIdDummyEntity createCustomIdDummyEntity () {
46+
47+ CustomIdDummyEntity entity = new CustomIdDummyEntity ();
48+ entity .name = "Custom ID Entity Name" ;
49+ return entity ;
50+ }
51+
4352 @ Test // DATAJDBC-551
4453 void deleteByName () {
4554
@@ -60,6 +69,26 @@ void deleteByName() {
6069 assertThat (count ).isEqualTo (0 );
6170 }
6271
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+
6392 private ChildElement createChildElement (String name ) {
6493
6594 ChildElement element = new ChildElement ();
@@ -76,10 +105,30 @@ private GrandChildElement createGrandChildElement(String content) {
76105 return element ;
77106 }
78107
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+
79124 interface DummyEntityRepository extends CrudRepository <DummyEntity , Long > {
80125 long deleteByName (String name );
81126 }
82127
128+ interface CustomIdDummyEntityRepository extends CrudRepository <CustomIdDummyEntity , Long > {
129+ long deleteByName (String name );
130+ }
131+
83132 @ Configuration
84133 @ Import (TestConfiguration .class )
85134 static class Config {
@@ -95,6 +144,11 @@ Class<?> testClass() {
95144 DummyEntityRepository dummyEntityRepository () {
96145 return factory .getRepository (DummyEntityRepository .class );
97146 }
147+
148+ @ Bean
149+ CustomIdDummyEntityRepository customIdDummyEntityRepository () {
150+ return factory .getRepository (CustomIdDummyEntityRepository .class );
151+ }
98152 }
99153
100154 static class DummyEntity {
@@ -118,4 +172,24 @@ static class GrandChildElement {
118172 @ Id private Long id ;
119173 }
120174
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+
121195}
0 commit comments