HHH-17303 Improve testJoinedInheritanceNativeQuery to operate on an entity with actual inheritance

This commit is contained in:
HARPER Jon 2023-10-10 13:00:00 +02:00 committed by Christian Beikov
parent c4251325ce
commit 090253260b
1 changed files with 18 additions and 2 deletions

View File

@ -27,7 +27,8 @@ import jakarta.persistence.InheritanceType;
*/ */
@DomainModel( @DomainModel(
annotatedClasses = { annotatedClasses = {
JoinedSubclassNativeQueryTest.Person.class JoinedSubclassNativeQueryTest.Person.class,
JoinedSubclassNativeQueryTest.Employee.class
} }
) )
@SessionFactory @SessionFactory
@ -56,7 +57,7 @@ public class JoinedSubclassNativeQueryTest {
public void testJoinedInheritanceNativeQuery(SessionFactoryScope scope) { public void testJoinedInheritanceNativeQuery(SessionFactoryScope scope) {
scope.inTransaction( scope.inTransaction(
session -> { session -> {
Person p = session.createNativeQuery( "select p.*, 0 as clazz_ from Person p", Person.class ).getSingleResult(); Person p = session.createNativeQuery( "select p.*, null as companyName, 0 as clazz_ from Person p", Person.class ).getSingleResult();
Assertions.assertNotNull( p ); Assertions.assertNotNull( p );
Assertions.assertEquals( p.getFirstName(), "Jan" ); Assertions.assertEquals( p.getFirstName(), "Jan" );
} }
@ -81,4 +82,19 @@ public class JoinedSubclassNativeQueryTest {
this.firstName = firstName; this.firstName = firstName;
} }
} }
@Entity(name = "Employee")
public static class Employee extends Person {
@Basic(optional = false)
private String companyName;
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
}
} }