Skip to content

Commit f163462

Browse files
mbelladebeikov
authored andcommitted
HHH-17225 Add test for issue
1 parent a03c1c0 commit f163462

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.query;
8+
9+
import org.hibernate.testing.orm.domain.gambit.EntityWithOneToOne;
10+
import org.hibernate.testing.orm.domain.gambit.SimpleEntity;
11+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
12+
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.Jira;
14+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
15+
import org.hibernate.testing.orm.junit.SessionFactory;
16+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
17+
import org.junit.jupiter.api.AfterAll;
18+
import org.junit.jupiter.api.BeforeAll;
19+
import org.junit.jupiter.api.Test;
20+
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
/**
24+
* @author Marco Belladelli
25+
*/
26+
@SessionFactory
27+
@DomainModel( annotatedClasses = { SimpleEntity.class, EntityWithOneToOne.class } )
28+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17225" )
29+
public class SelectForeignKeyWithMissingFromTest {
30+
@BeforeAll
31+
public void setUp(SessionFactoryScope scope) {
32+
scope.inTransaction( session -> session.persist( new SimpleEntity( 1, "test" ) ) );
33+
}
34+
35+
@AfterAll
36+
public void tearDown(SessionFactoryScope scope) {
37+
scope.inTransaction( session -> session.createMutationQuery( "delete from SimpleEntity" ).executeUpdate() );
38+
}
39+
40+
@Test
41+
public void testRightJoin(SessionFactoryScope scope) {
42+
scope.inTransaction( session -> {
43+
final Integer result = session.createQuery(
44+
"select o.id from EntityWithOneToOne e right join e.other o",
45+
Integer.class
46+
).getSingleResult();
47+
assertThat( result ).isEqualTo( 1 );
48+
} );
49+
}
50+
51+
@Test
52+
public void testRightJoinEntityPath(SessionFactoryScope scope) {
53+
scope.inTransaction( session -> {
54+
final SimpleEntity result = session.createQuery(
55+
"select o from EntityWithOneToOne e right join e.other o",
56+
SimpleEntity.class
57+
).getSingleResult();
58+
assertThat( result.getId() ).isEqualTo( 1 );
59+
} );
60+
}
61+
62+
@Test
63+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsFullJoin.class )
64+
public void testFullJoin(SessionFactoryScope scope) {
65+
scope.inTransaction( session -> {
66+
final Integer result = session.createQuery(
67+
"select o.id from EntityWithOneToOne e full join e.other o",
68+
Integer.class
69+
).getSingleResult();
70+
assertThat( result ).isEqualTo( 1 );
71+
} );
72+
}
73+
74+
@Test
75+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsFullJoin.class )
76+
public void testFullJoinEntityPath(SessionFactoryScope scope) {
77+
scope.inTransaction( session -> {
78+
final SimpleEntity result = session.createQuery(
79+
"select o from EntityWithOneToOne e full join e.other o",
80+
SimpleEntity.class
81+
).getSingleResult();
82+
assertThat( result.getId() ).isEqualTo( 1 );
83+
} );
84+
}
85+
}

0 commit comments

Comments
 (0)