Skip to content

Commit 2b8947e

Browse files
committed
HHH-17332 Add test for issue
1 parent 4d693f4 commit 2b8947e

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
5+
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
6+
*/
7+
package org.hibernate.orm.test.hql;
8+
9+
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
10+
import org.hibernate.testing.orm.junit.DomainModel;
11+
import org.hibernate.testing.orm.junit.Jira;
12+
import org.hibernate.testing.orm.junit.SessionFactory;
13+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
14+
import org.junit.jupiter.api.AfterAll;
15+
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.Test;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
/**
21+
* @author Marco Belladelli
22+
*/
23+
@DomainModel( annotatedClasses = BasicEntity.class )
24+
@SessionFactory
25+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17332" )
26+
public class InSubqueryPredicateAnonymousTupleTest {
27+
@BeforeAll
28+
public void setUp(SessionFactoryScope scope) {
29+
scope.inTransaction( session -> session.persist( new BasicEntity( 1, "test" ) ) );
30+
}
31+
32+
@AfterAll
33+
public void tearDown(SessionFactoryScope scope) {
34+
scope.inTransaction( session -> session.createMutationQuery( "delete from BasicEntity" ).executeUpdate() );
35+
}
36+
37+
@Test
38+
public void testSimpleInSubqueryPredicate(SessionFactoryScope scope) {
39+
scope.inTransaction( session -> {
40+
final String result = session.createQuery(
41+
"select sub.data from (select e.id id, e.data data from BasicEntity e) sub" +
42+
" where sub.data in (select e.data from BasicEntity e)",
43+
String.class
44+
).getSingleResult();
45+
assertThat( result ).isEqualTo( "test" );
46+
} );
47+
}
48+
49+
@Test
50+
public void testTupleInSubqueryPredicate(SessionFactoryScope scope) {
51+
scope.inTransaction( session -> {
52+
// note : without cast(sub.data as string) Sybase jTDS fails with "TDS Protocol error: Invalid TDS data type"
53+
final String result = session.createQuery(
54+
"select cast(sub.data as string) from (select e.id id, e.data data from BasicEntity e) sub" +
55+
" where (sub.id, sub.data) in (select e.id, e.data from BasicEntity e)",
56+
String.class
57+
).getSingleResult();
58+
assertThat( result ).isEqualTo( "test" );
59+
} );
60+
}
61+
}

0 commit comments

Comments
 (0)