1515 */
1616package org .springframework .data .jdbc .core ;
1717
18+ import static java .util .Arrays .*;
1819import static java .util .Collections .*;
1920import static org .assertj .core .api .Assertions .*;
2021import static org .assertj .core .api .SoftAssertions .*;
2122import static org .springframework .data .jdbc .testing .TestDatabaseFeatures .Feature .*;
2223import static org .springframework .test .context .TestExecutionListeners .MergeMode .*;
2324
25+ import lombok .Data ;
26+ import lombok .EqualsAndHashCode ;
27+ import lombok .Value ;
28+ import lombok .With ;
29+
2430import java .time .LocalDateTime ;
2531import java .util .ArrayList ;
26- import java .util .Arrays ;
2732import java .util .Collections ;
2833import java .util .HashMap ;
2934import java .util .HashSet ;
4449import org .springframework .dao .IncorrectUpdateSemanticsDataAccessException ;
4550import org .springframework .dao .OptimisticLockingFailureException ;
4651import org .springframework .data .annotation .Id ;
52+ import org .springframework .data .annotation .PersistenceConstructor ;
4753import org .springframework .data .annotation .ReadOnlyProperty ;
4854import org .springframework .data .annotation .Version ;
4955import org .springframework .data .domain .PageRequest ;
5662import org .springframework .data .jdbc .testing .TestDatabaseFeatures ;
5763import org .springframework .data .relational .core .conversion .DbActionExecutionException ;
5864import org .springframework .data .relational .core .mapping .Column ;
65+ import org .springframework .data .relational .core .mapping .MappedCollection ;
5966import org .springframework .data .relational .core .mapping .RelationalMappingContext ;
6067import org .springframework .data .relational .core .mapping .Table ;
6168import org .springframework .jdbc .core .namedparam .NamedParameterJdbcOperations ;
6471import org .springframework .test .context .junit .jupiter .SpringExtension ;
6572import org .springframework .transaction .annotation .Transactional ;
6673
67- import lombok .Data ;
68- import lombok .EqualsAndHashCode ;
69- import lombok .Value ;
70- import lombok .With ;
71-
7274/**
7375 * Integration tests for {@link JdbcAggregateTemplate}.
7476 *
@@ -502,6 +504,21 @@ public void saveAndLoadAnEntityWithListOfElementsWithoutId() {
502504 assertThat (reloaded .content ).extracting (e -> e .content ).containsExactly ("content" );
503505 }
504506
507+ @ Test // GH-498 DATAJDBC-273
508+ @ EnabledOnFeature (SUPPORTS_QUOTED_IDS )
509+ public void saveAndLoadAnEntityWithListOfElementsInConstructor () {
510+
511+ ElementNoId element = new ElementNoId ();
512+ element .content = "content" ;
513+ ListParentAllArgs entity = new ListParentAllArgs ("name" , asList (element ));
514+
515+ entity = template .save (entity );
516+
517+ ListParentAllArgs reloaded = template .findById (entity .id , ListParentAllArgs .class );
518+
519+ assertThat (reloaded .content ).extracting (e -> e .content ).containsExactly ("content" );
520+ }
521+
505522 @ Test // DATAJDBC-259
506523 @ EnabledOnFeature (SUPPORTS_ARRAYS )
507524 public void saveAndLoadAnEntityWithArray () {
@@ -544,7 +561,7 @@ public void saveAndLoadAnEntityWithMultidimensionalArray() {
544561 public void saveAndLoadAnEntityWithList () {
545562
546563 ListOwner arrayOwner = new ListOwner ();
547- arrayOwner .digits .addAll (Arrays . asList ("one" , "two" , "three" ));
564+ arrayOwner .digits .addAll (asList ("one" , "two" , "three" ));
548565
549566 ListOwner saved = template .save (arrayOwner );
550567
@@ -554,15 +571,15 @@ public void saveAndLoadAnEntityWithList() {
554571
555572 assertThat (reloaded ).isNotNull ();
556573 assertThat (reloaded .id ).isEqualTo (saved .id );
557- assertThat (reloaded .digits ).isEqualTo (Arrays . asList ("one" , "two" , "three" ));
574+ assertThat (reloaded .digits ).isEqualTo (asList ("one" , "two" , "three" ));
558575 }
559576
560577 @ Test // GH-1033
561578 @ EnabledOnFeature (SUPPORTS_ARRAYS )
562579 public void saveAndLoadAnEntityWithListOfDouble () {
563580
564581 DoubleListOwner doubleListOwner = new DoubleListOwner ();
565- doubleListOwner .digits .addAll (Arrays . asList (1.2 , 1.3 , 1.4 ));
582+ doubleListOwner .digits .addAll (asList (1.2 , 1.3 , 1.4 ));
566583
567584 DoubleListOwner saved = template .save (doubleListOwner );
568585
@@ -572,15 +589,15 @@ public void saveAndLoadAnEntityWithListOfDouble() {
572589
573590 assertThat (reloaded ).isNotNull ();
574591 assertThat (reloaded .id ).isEqualTo (saved .id );
575- assertThat (reloaded .digits ).isEqualTo (Arrays . asList (1.2 , 1.3 , 1.4 ));
592+ assertThat (reloaded .digits ).isEqualTo (asList (1.2 , 1.3 , 1.4 ));
576593 }
577594
578595 @ Test // GH-1033, GH-1046
579596 @ EnabledOnFeature (SUPPORTS_ARRAYS )
580597 public void saveAndLoadAnEntityWithListOfFloat () {
581598
582599 FloatListOwner floatListOwner = new FloatListOwner ();
583- final List <Float > values = Arrays . asList (1.2f , 1.3f , 1.4f );
600+ final List <Float > values = asList (1.2f , 1.3f , 1.4f );
584601 floatListOwner .digits .addAll (values );
585602
586603 FloatListOwner saved = template .save (floatListOwner );
@@ -599,7 +616,7 @@ public void saveAndLoadAnEntityWithListOfFloat() {
599616 public void saveAndLoadAnEntityWithSet () {
600617
601618 SetOwner setOwner = new SetOwner ();
602- setOwner .digits .addAll (Arrays . asList ("one" , "two" , "three" ));
619+ setOwner .digits .addAll (asList ("one" , "two" , "three" ));
603620
604621 SetOwner saved = template .save (setOwner );
605622
@@ -609,7 +626,7 @@ public void saveAndLoadAnEntityWithSet() {
609626
610627 assertThat (reloaded ).isNotNull ();
611628 assertThat (reloaded .id ).isEqualTo (saved .id );
612- assertThat (reloaded .digits ).isEqualTo (new HashSet <>(Arrays . asList ("one" , "two" , "three" )));
629+ assertThat (reloaded .digits ).isEqualTo (new HashSet <>(asList ("one" , "two" , "three" )));
613630 }
614631
615632 @ Test // DATAJDBC-327
@@ -1011,13 +1028,37 @@ static class ChildNoId {
10111028 private String content ;
10121029 }
10131030
1031+ @ Table ("LIST_PARENT" )
10141032 static class ListParent {
10151033
10161034 @ Column ("id4" ) @ Id private Long id ;
10171035 String name ;
1036+ @ MappedCollection (idColumn = "LIST_PARENT" )
10181037 List <ElementNoId > content = new ArrayList <>();
10191038 }
10201039
1040+ @ Table ("LIST_PARENT" )
1041+ static class ListParentAllArgs {
1042+
1043+ @ Column ("id4" ) @ Id
1044+ private final Long id ;
1045+ private final String name ;
1046+ @ MappedCollection (idColumn = "LIST_PARENT" )
1047+ private final List <ElementNoId > content = new ArrayList <>();
1048+
1049+ @ PersistenceConstructor
1050+ ListParentAllArgs (Long id , String name , List <ElementNoId > content ) {
1051+
1052+ this .id = id ;
1053+ this .name = name ;
1054+ this .content .addAll (content );
1055+ }
1056+
1057+ ListParentAllArgs (String name , List <ElementNoId > content ) {
1058+ this (null , name , content );
1059+ }
1060+ }
1061+
10211062 static class ElementNoId {
10221063 private String content ;
10231064 }
0 commit comments