2121import jakarta .persistence .Enumerated ;
2222import jakarta .persistence .Id ;
2323
24- import static org .assertj . core .api .Assertions .assertThat ;
24+ import static org .junit . jupiter .api .Assertions .assertEquals ;
2525
2626/**
2727 * @author Marco Belladelli
2828 */
2929@ DomainModel ( annotatedClasses = {
3030 BasicEntity .class ,
3131 InSubqueryPredicateAnonymousTupleTest .TestEntity .class ,
32+ InSubqueryPredicateAnonymousTupleTest .MarketSale .class ,
33+ InSubqueryPredicateAnonymousTupleTest .Peach .class
3234} )
3335@ SessionFactory
3436@ Jira ( "https://hibernate.atlassian.net/browse/HHH-17332" )
@@ -46,6 +48,8 @@ public void setUp(SessionFactoryScope scope) {
4648 @ AfterAll
4749 public void tearDown (SessionFactoryScope scope ) {
4850 scope .inTransaction ( session -> session .createMutationQuery ( "delete from BasicEntity" ).executeUpdate () );
51+ scope .inTransaction ( session -> session .createMutationQuery ( "delete from MarketSale" ).executeUpdate () );
52+ scope .inTransaction ( session -> session .createMutationQuery ( "delete from Peach" ).executeUpdate () );
4953 }
5054
5155 @ Test
@@ -56,7 +60,7 @@ public void testSimpleInSubqueryPredicate(SessionFactoryScope scope) {
5660 " where sub.data in (select e.data from BasicEntity e)" ,
5761 String .class
5862 ).getSingleResult ();
59- assertThat ( result ). isEqualTo ( "test" );
63+ assertEquals ( "test" , result );
6064 } );
6165 }
6266
@@ -69,7 +73,7 @@ public void testTupleInSubqueryPredicate(SessionFactoryScope scope) {
6973 " where (sub.id, sub.data) in (select e.id, e.data from BasicEntity e)" ,
7074 String .class
7175 ).getSingleResult ();
72- assertThat ( result ). isEqualTo ( "test" );
76+ assertEquals ( "test" , result );
7377 } );
7478 }
7579
@@ -81,7 +85,7 @@ public void testConvertedAttributeTuple(SessionFactoryScope scope) {
8185 "(select t2.id, t2.money from TestEntity t2)" ,
8286 TestEntity .class
8387 ).getSingleResult ();
84- assertThat ( result .getMoney ().getCents () ). isEqualTo ( 100L );
88+ assertEquals ( 100L , result .getMoney ().getCents () );
8589 } );
8690 }
8791
@@ -90,13 +94,29 @@ public void testEnumeratedAttributeTuple(SessionFactoryScope scope) {
9094 scope .inTransaction ( session -> {
9195 final TestEntity result = session .createQuery (
9296 "select t from TestEntity t where (t.id, t.status) in " +
93- "(select t2.id, t2.status from TestEntity t2)" ,
97+ "(select t2.id, t2.status from TestEntity t2)" ,
9498 TestEntity .class
9599 ).getSingleResult ();
96- assertThat ( result .getStatus () ). isEqualTo ( Status . VALID );
100+ assertEquals ( Status . VALID , result .getStatus () );
97101 } );
98102 }
99103
104+ @ Test
105+ @ Jira (value = "https://hibernate.atlassian.net/browse/HHH-17630" )
106+ public void testTupleInSubqueryPredicate2 (SessionFactoryScope scope ) {
107+ scope .inTransaction (
108+ session -> {
109+ session .persist ( new Peach (1 , "Green peach" , FruitColor .GREEN ) );
110+ session .persist ( new MarketSale (1 , "Green peach" , FruitColor .GREEN ) );
111+
112+ int count = session .createMutationQuery ( "delete from MarketSale m where "
113+ + "(m.fruitColor, m.fruitName) in (select p.color, p.name from Peach p)" ).executeUpdate ();
114+ assertEquals ( 1 , count );
115+ }
116+ );
117+
118+ }
119+
100120 @ Entity ( name = "TestEntity" )
101121 public static class TestEntity {
102122 @ Id
@@ -154,4 +174,47 @@ public Money convertToEntityAttribute(Long dbData) {
154174 return dbData == null ? null : new Money ( dbData );
155175 }
156176 }
177+ @ Entity (name = "MarketSale" )
178+ public static class MarketSale
179+ {
180+ @ Id
181+ private Integer id ;
182+ private String fruitName ;
183+ @ Enumerated (EnumType .STRING )
184+ private FruitColor fruitColor ;
185+
186+ public MarketSale () {
187+ }
188+
189+ public MarketSale (Integer id , String fruitName , FruitColor fruitColor ) {
190+ this .id = id ;
191+ this .fruitName = fruitName ;
192+ this .fruitColor = fruitColor ;
193+ }
194+ }
195+
196+ @ Entity (name = "Peach" )
197+ public static class Peach
198+ {
199+ @ Id
200+ private Integer id ;
201+ private String name ;
202+ @ Enumerated (EnumType .STRING )
203+ private FruitColor color ;
204+
205+ public Peach () {
206+ }
207+
208+ public Peach (Integer id , String name , FruitColor color ) {
209+ this .id = id ;
210+ this .name = name ;
211+ this .color = color ;
212+ }
213+ }
214+
215+ public enum FruitColor
216+ {
217+ GREEN
218+ }
219+
157220}
0 commit comments