@@ -811,4 +811,162 @@ class SaveCommandTest : AbstractMutationTest() {
811
811
}
812
812
}
813
813
}
814
+
815
+ @Test
816
+ fun testIssue1071ByOneAssociationByQuery () {
817
+ resetIdentity(null , " AUTHOR" )
818
+ resetIdentity(null , " BOOK" )
819
+ val author = Author {
820
+ firstName = " Michael"
821
+ lastName = " Simpson"
822
+ gender = Gender .MALE
823
+ books().addBy {
824
+ name = " Learning GraphQL"
825
+ edition = 1
826
+ price = BigDecimal .valueOf(1.0 )
827
+ }
828
+ }
829
+ executeAndExpectResult({ con ->
830
+ sqlClient {
831
+ setDialect(object : H2Dialect () {
832
+ override fun isUpsertSupported (): Boolean = false
833
+ })
834
+ setIdGenerator(IdentityIdGenerator .INSTANCE )
835
+ }.entities.forConnection(con).save(author) {
836
+ setAssociatedMode(Author ::books, AssociatedSaveMode .APPEND_IF_ABSENT )
837
+ }
838
+ }) {
839
+ statement {
840
+ sql(
841
+ """ select tb_1_.ID, tb_1_.FIRST_NAME, tb_1_.LAST_NAME
842
+ |from AUTHOR tb_1_
843
+ |where (tb_1_.FIRST_NAME, tb_1_.LAST_NAME) = (?, ?)""" .trimMargin()
844
+ )
845
+ }
846
+ statement {
847
+ sql(
848
+ """ insert into AUTHOR(FIRST_NAME, LAST_NAME, GENDER)
849
+ |values(?, ?, ?)""" .trimMargin()
850
+ )
851
+ }
852
+ statement {
853
+ sql(
854
+ """ select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION
855
+ |from BOOK tb_1_
856
+ |where (tb_1_.NAME, tb_1_.EDITION) = (?, ?)""" .trimMargin()
857
+ )
858
+ }
859
+ statement {
860
+ sql(
861
+ """ insert into BOOK_AUTHOR_MAPPING(AUTHOR_ID, BOOK_ID)
862
+ |values(?, ?)""" .trimMargin()
863
+ )
864
+ }
865
+ entity {
866
+ modified(
867
+ """ {
868
+ |--->"id":100,
869
+ |--->"firstName":"Michael",
870
+ |--->"lastName":"Simpson",
871
+ |--->"gender":"MALE",
872
+ |--->"books":[
873
+ |--->--->{
874
+ |--->--->--->"id":1,
875
+ |--->--->--->"name":"Learning GraphQL",
876
+ |--->--->--->"edition":1,
877
+ |--->--->--->"price":1.0
878
+ |--->--->}
879
+ |--->]
880
+ |}""" .trimMargin()
881
+ )
882
+ }
883
+ }
884
+ }
885
+
886
+ @Test
887
+ fun testIssue1071ByTwoAssociationsByQuery () {
888
+ resetIdentity(null , " AUTHOR" )
889
+ resetIdentity(null , " BOOK" )
890
+ val author = Author {
891
+ firstName = " Michael"
892
+ lastName = " Simpson"
893
+ gender = Gender .MALE
894
+ books().addBy {
895
+ name = " Learning GraphQL"
896
+ edition = 3
897
+ price = BigDecimal .valueOf(1.0 )
898
+ }
899
+ books().addBy {
900
+ name = " Learning GraphQL"
901
+ edition = 4
902
+ price = BigDecimal .valueOf(1.0 )
903
+ }
904
+ }
905
+ executeAndExpectResult({ con ->
906
+ sqlClient {
907
+ setDialect(object : H2Dialect () {
908
+ override fun isUpsertSupported (): Boolean = false
909
+ })
910
+ setIdGenerator(IdentityIdGenerator .INSTANCE )
911
+ }.entities.forConnection(con).save(author) {
912
+ setAssociatedMode(Author ::books, AssociatedSaveMode .APPEND_IF_ABSENT )
913
+ }
914
+ }) {
915
+ statement {
916
+ sql(
917
+ """ select tb_1_.ID, tb_1_.FIRST_NAME, tb_1_.LAST_NAME
918
+ |from AUTHOR tb_1_
919
+ |where (tb_1_.FIRST_NAME, tb_1_.LAST_NAME) = (?, ?)""" .trimMargin()
920
+ )
921
+ }
922
+ statement {
923
+ sql(
924
+ """ insert into AUTHOR(FIRST_NAME, LAST_NAME, GENDER)
925
+ |values(?, ?, ?)""" .trimMargin()
926
+ )
927
+ }
928
+ statement {
929
+ sql(
930
+ """ select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION
931
+ |from BOOK tb_1_
932
+ |where (tb_1_.NAME, tb_1_.EDITION) in ((?, ?), (?, ?))""" .trimMargin()
933
+ )
934
+ }
935
+ statement {
936
+ sql(
937
+ """ insert into BOOK(NAME, EDITION, PRICE)
938
+ |values(?, ?, ?)""" .trimMargin()
939
+ )
940
+ }
941
+ statement {
942
+ sql(
943
+ """ insert into BOOK_AUTHOR_MAPPING(AUTHOR_ID, BOOK_ID)
944
+ |values(?, ?)""" .trimMargin()
945
+ )
946
+ }
947
+ entity {
948
+ modified(
949
+ """ {
950
+ |--->"id":100,
951
+ |--->"firstName":"Michael",
952
+ |--->"lastName":"Simpson",
953
+ |--->"gender":"MALE",
954
+ |--->"books":[
955
+ |--->--->{
956
+ |--->--->--->"id":3,
957
+ |--->--->--->"name":"Learning GraphQL",
958
+ |--->--->--->"edition":3,
959
+ |--->--->--->"price":1.0
960
+ |--->--->},{
961
+ |--->--->--->"id":100,
962
+ |--->--->--->"name":"Learning GraphQL",
963
+ |--->--->--->"edition":4,
964
+ |--->--->--->"price":1.0
965
+ |--->--->}
966
+ |--->]
967
+ |}""" .trimMargin()
968
+ )
969
+ }
970
+ }
971
+ }
814
972
}
0 commit comments