HHH-12565 - Add some additional tests
Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
d61719acd5
commit
c8234fc493
|
@ -6,18 +6,25 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.unionsubclass3;
|
package org.hibernate.orm.test.unionsubclass3;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.testing.orm.junit.JiraKey;
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.hibernate.Transaction;
|
||||||
|
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Inheritance;
|
import jakarta.persistence.Inheritance;
|
||||||
import jakarta.persistence.InheritanceType;
|
import jakarta.persistence.InheritanceType;
|
||||||
import jakarta.persistence.ManyToOne;
|
import jakarta.persistence.ManyToOne;
|
||||||
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -30,8 +37,15 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
return new Class[] {Child.class, Parent.class, Father.class, Mother.class};
|
return new Class[] {Child.class, Parent.class, Father.class, Mother.class};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
|
session.createMutationQuery( "delete from Parent" ).executeUpdate();
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-12114" )
|
@JiraKey( value = "HHH-12114")
|
||||||
public void testUnionSubclassClassResults() {
|
public void testUnionSubclassClassResults() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
Father father = new Father();
|
Father father = new Father();
|
||||||
|
@ -92,7 +106,7 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-12565" )
|
@JiraKey( value = "HHH-12565")
|
||||||
public void typeOfLeafTPC() {
|
public void typeOfLeafTPC() {
|
||||||
doInHibernate( this::sessionFactory, session -> {
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
List results = session.createQuery(
|
List results = session.createQuery(
|
||||||
|
@ -104,6 +118,62 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@JiraKey( value = "HHH-12565")
|
||||||
|
public void typeOfLeafTPCWithoutWhere() {
|
||||||
|
doInHibernate( this::sessionFactory, session -> {
|
||||||
|
List results = session.createQuery("select TYPE(f) from Father f")
|
||||||
|
.getResultList();
|
||||||
|
assertEquals(0, results.size());
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@JiraKey( value = "HHH-12565")
|
||||||
|
public void typeOfParentInheritorTPCCriteriaTest() {
|
||||||
|
inSession(
|
||||||
|
session -> {
|
||||||
|
Transaction transaction = session.beginTransaction();
|
||||||
|
Father father = new Father();
|
||||||
|
father.id = 42L;
|
||||||
|
session.persist( father );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
HibernateCriteriaBuilder cb = session.getSessionFactory().getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Parent> query = cb.createQuery( Parent.class );
|
||||||
|
Root<Parent> root = query.from( Parent.class );
|
||||||
|
query.where( cb.equal( root.type(), cb.literal(Father.class) ) );
|
||||||
|
List<Parent> result = session.createQuery( query ).getResultList();
|
||||||
|
Assertions.assertEquals( result, List.of( father ) );
|
||||||
|
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@JiraKey( value = "HHH-12565")
|
||||||
|
public void typeOfTPCCriteriaTest() {
|
||||||
|
inSession(
|
||||||
|
session -> {
|
||||||
|
Transaction transaction = session.beginTransaction();
|
||||||
|
Father father = new Father();
|
||||||
|
father.id = 42L;
|
||||||
|
session.persist( father );
|
||||||
|
session.flush();
|
||||||
|
|
||||||
|
HibernateCriteriaBuilder cb = session.getSessionFactory().getCriteriaBuilder();
|
||||||
|
CriteriaQuery<Class> query = cb.createQuery( Class.class );
|
||||||
|
Root<Parent> root = query.from( Parent.class );
|
||||||
|
query.select( root.type() );
|
||||||
|
List<Class> result = session.createQuery( query ).getResultList();
|
||||||
|
Assertions.assertEquals( List.of( Father.class ), result );
|
||||||
|
|
||||||
|
transaction.rollback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Entity(name = "Child")
|
@Entity(name = "Child")
|
||||||
public static class Child
|
public static class Child
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue