Skip to content

Commit

Permalink
HHH-16974 Add test for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 authored and beikov committed Feb 7, 2024
1 parent 0403d12 commit e7f9875
Showing 1 changed file with 115 additions and 0 deletions.
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;
}
}

}

0 comments on commit e7f9875

Please sign in to comment.