-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...te-core/src/test/java/org/hibernate/orm/test/hql/QueryComparingAssociationToNullTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package org.hibernate.orm.test.hql; | ||
|
||
import java.time.LocalDate; | ||
|
||
import org.hibernate.dialect.DerbyDialect; | ||
|
||
import org.hibernate.testing.orm.junit.DomainModel; | ||
import org.hibernate.testing.orm.junit.JiraKey; | ||
import org.hibernate.testing.orm.junit.SessionFactory; | ||
import org.hibernate.testing.orm.junit.SessionFactoryScope; | ||
import org.hibernate.testing.orm.junit.SkipForDialect; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Query; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
||
@DomainModel( | ||
annotatedClasses = { | ||
QueryComparingAssociationToNullTest.Parent.class, | ||
QueryComparingAssociationToNullTest.Child.class, | ||
} | ||
) | ||
@SessionFactory | ||
@JiraKey("HHH-16974") | ||
@SkipForDialect( dialectClass = DerbyDialect.class, reason = "it does not like `= null`") | ||
public class QueryComparingAssociationToNullTest { | ||
|
||
@Test | ||
public void testQuery(SessionFactoryScope scope) { | ||
LocalDate date = LocalDate.now(); | ||
scope.inTransaction( | ||
session -> { | ||
Child child = new Child( 1, "first" ); | ||
Parent parent = new Parent( 1, date, child ); | ||
session.persist( child ); | ||
session.persist( parent ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
Query query = session.createQuery( | ||
"SELECT p FROM Parent p WHERE p.child = NULL ", | ||
Parent.class | ||
); | ||
query.getResultList(); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
Query query = session.createQuery( | ||
"SELECT p FROM Parent p WHERE p.child = NULL OR p.date = :date ", | ||
Parent.class | ||
).setParameter( "date", date ); | ||
assertThat(query.getResultList().size()).isEqualTo( 1 ); | ||
} | ||
); | ||
|
||
scope.inTransaction( | ||
session -> { | ||
Query query = session.createQuery( | ||
"SELECT p FROM Parent p WHERE p.child = NULL OR p.date = NULL ", | ||
Parent.class | ||
); | ||
query.getResultList(); | ||
} | ||
); | ||
} | ||
|
||
@Entity(name = "Parent") | ||
public static class Parent { | ||
|
||
@Id | ||
private Integer id; | ||
|
||
@Column(name = "COLUMN_DATE") | ||
private LocalDate date; | ||
|
||
@ManyToOne | ||
private Child child; | ||
|
||
|
||
public Parent() { | ||
} | ||
|
||
public Parent(Integer id, LocalDate date, Child child) { | ||
this.id = id; | ||
this.date = date; | ||
this.child = child; | ||
} | ||
} | ||
|
||
@Entity(name = "Child") | ||
public static class Child { | ||
@Id | ||
private Integer id; | ||
|
||
private String name; | ||
|
||
public Child() { | ||
} | ||
|
||
public Child(Integer id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
} | ||
|
||
} |