Skip to content

Commit d914cdd

Browse files
committed
HHH-19116 Add test for issue
1 parent 76359ad commit d914cdd

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/query/LeftJoinNullnessPredicateQueryTest.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.List;
88

99
import org.hibernate.testing.orm.junit.DomainModel;
10+
import org.hibernate.testing.orm.junit.Jira;
1011
import org.hibernate.testing.orm.junit.SessionFactory;
1112
import org.hibernate.testing.orm.junit.SessionFactoryScope;
1213
import org.junit.jupiter.api.AfterAll;
@@ -27,7 +28,11 @@
2728
@DomainModel( annotatedClasses = {
2829
LeftJoinNullnessPredicateQueryTest.Author.class,
2930
LeftJoinNullnessPredicateQueryTest.Book.class
30-
} )
31+
})
32+
@Jira( "https://hibernate.atlassian.net/browse/HHH-16505" )
33+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17379" )
34+
@Jira( "https://hibernate.atlassian.net/browse/HHH-17397" )
35+
@Jira( "https://hibernate.atlassian.net/browse/HHH-19116" )
3136
public class LeftJoinNullnessPredicateQueryTest {
3237
@BeforeAll
3338
public void setUp(SessionFactoryScope scope) {
@@ -78,6 +83,19 @@ public void testIsNotNull(SessionFactoryScope scope) {
7883
} );
7984
}
8085

86+
@Test
87+
public void testIsNullImplicit(SessionFactoryScope scope) {
88+
scope.inTransaction( session -> {
89+
final List<Book> resultList = session.createQuery(
90+
"select book from Book book " +
91+
"where book.author is null",
92+
Book.class
93+
).getResultList();
94+
assertThat( resultList ).hasSize( 1 );
95+
assertThat( resultList.get( 0 ).getTitle() ).isEqualTo( "Unknown Author" );
96+
} );
97+
}
98+
8199
@Test
82100
public void testDereferenceIsNull(SessionFactoryScope scope) {
83101
scope.inTransaction( session -> {
@@ -106,6 +124,33 @@ public void testDereferenceIsNotNull(SessionFactoryScope scope) {
106124
} );
107125
}
108126

127+
@Test
128+
public void testFkImplicitIsNull(SessionFactoryScope scope) {
129+
scope.inTransaction( session -> {
130+
final List<Book> resultList = session.createQuery(
131+
"select book from Book book " +
132+
"where fk(book.author) is null",
133+
Book.class
134+
).getResultList();
135+
assertThat( resultList ).hasSize( 1 );
136+
assertThat( resultList.get( 0 ).getTitle() ).isEqualTo( "Unknown Author" );
137+
} );
138+
}
139+
140+
@Test
141+
public void testFkImplicitIsNullJoinOr(SessionFactoryScope scope) {
142+
scope.inTransaction( session -> {
143+
final List<Book> resultList = session.createQuery(
144+
"select book from Book book " +
145+
"left join book.author a " +
146+
"where fk(book.author) is null or a.name = 'Stephen King'",
147+
Book.class
148+
).getResultList();
149+
assertThat( resultList ).hasSize( 1 );
150+
assertThat( resultList.get( 0 ).getTitle() ).isEqualTo( "Unknown Author" );
151+
} );
152+
}
153+
109154
@Test
110155
public void testIsNotNullWithCondition(SessionFactoryScope scope) {
111156
scope.inTransaction( session -> {

0 commit comments

Comments
 (0)