HHH-15278 Add test for issue

This commit is contained in:
Andrea Boriero 2022-05-17 12:00:07 +02:00 committed by Andrea Boriero
parent e87ad39dd6
commit 3251d5e9d0
1 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,90 @@
package org.hibernate.orm.test.query;
import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertNull;
@DomainModel(
annotatedClasses = { SelectNullQueryTest.Person.class }
)
@SessionFactory
@TestForIssue(jiraKey = "HHH-15278")
public class SelectNullQueryTest {
@BeforeEach
public void setUp(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Person person = new Person( 1l, "Fab" );
session.persist( person );
}
);
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete from Person" ).executeUpdate();
}
);
}
@Test
public void testSelectNull(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List result = session.createQuery( "select null from Person p" ).list();
assertThat( result.size(), is( 1 ) );
assertNull( result.get( 0 ) );
}
);
}
@Entity(name = "Person")
@Table(name = "PERSON_TABLE")
public static class Person {
@Id
private Long id;
private String name;
public Person() {
}
public Person(Long id, String name) {
this.id = id;
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}