Skip to content

Commit 1e4b113

Browse files
committed
HHH-18681 Add test for issue
1 parent d702496 commit 1e4b113

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* SPDX-License-Identifier: LGPL-2.1-or-later
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.query;
6+
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.Id;
10+
import org.hibernate.testing.orm.junit.DomainModel;
11+
import org.hibernate.testing.orm.junit.JiraKey;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.BeforeEach;
15+
import org.junit.jupiter.api.Test;
16+
17+
import java.util.List;
18+
19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
20+
21+
22+
@DomainModel(
23+
annotatedClasses = {
24+
SubQuerySelectCaseWhenTest.TestEntity.class,
25+
}
26+
)
27+
@SessionFactory
28+
@JiraKey("HHH-18681")
29+
public class SubQuerySelectCaseWhenTest {
30+
31+
@BeforeEach
32+
public void setUp(SessionFactoryScope scope) {
33+
scope.inTransaction(
34+
session -> {
35+
session.persist( new TestEntity( "A" ) );
36+
session.persist( new TestEntity( "B" ) );
37+
session.persist( new TestEntity( "C" ) );
38+
}
39+
);
40+
}
41+
42+
@Test
43+
public void testSelectCase(SessionFactoryScope scope) {
44+
scope.inTransaction( session -> {
45+
List<Integer> result = session.createQuery( "select "
46+
+ " (select "
47+
+ " case "
48+
+ " when "
49+
+ " t.name = ?1 "
50+
+ " then 0 "
51+
+ " else 1 "
52+
+ " end)"
53+
+ " from TestEntity t order by t.name", Integer.class )
54+
.setParameter( 1, "A" )
55+
.list();
56+
assertThat( result.size() ).isEqualTo( 3 );
57+
assertThat( result.get( 0 ) ).isEqualTo( 0 );
58+
assertThat( result.get( 1 ) ).isEqualTo( 1 );
59+
assertThat( result.get( 2 ) ).isEqualTo( 1 );
60+
} );
61+
}
62+
63+
@Entity(name = "TestEntity")
64+
public class TestEntity {
65+
66+
@Id
67+
@GeneratedValue
68+
private Long id;
69+
70+
private String name;
71+
72+
public TestEntity() {
73+
}
74+
75+
public TestEntity(String name) {
76+
this.name = name;
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)