From a9c2ea3a46425e85382f60a78a76948d8fb5d520 Mon Sep 17 00:00:00 2001 From: Nathan Xu Date: Thu, 12 Mar 2020 16:38:37 -0400 Subject: [PATCH] add 'Criteria' testing --- .../entitygraph/CriteriaEntityGraphTest.java | 455 ++++++++++++++++++ .../hql/entitygraph/HqlEntityGraphTest.java | 58 +-- 2 files changed, 484 insertions(+), 29 deletions(-) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/entitygraph/CriteriaEntityGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/entitygraph/CriteriaEntityGraphTest.java index 00effa2a4959..3c91e91a0027 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/entitygraph/CriteriaEntityGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/criteria/entitygraph/CriteriaEntityGraphTest.java @@ -6,8 +6,463 @@ */ package org.hibernate.orm.test.query.criteria.entitygraph; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import javax.persistence.ElementCollection; +import javax.persistence.Embeddable; +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; + +import org.hibernate.engine.spi.EffectiveEntityGraph; +import org.hibernate.engine.spi.LoadQueryInfluencers; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.graph.GraphSemantic; +import org.hibernate.graph.spi.RootGraphImplementor; +import org.hibernate.metamodel.mapping.EntityValuedModelPart; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping; +import org.hibernate.query.hql.spi.HqlQueryImplementor; +import org.hibernate.query.spi.QueryImplementor; +import org.hibernate.query.sqm.internal.QuerySqmImpl; +import org.hibernate.query.sqm.sql.SqmSelectTranslation; +import org.hibernate.query.sqm.sql.internal.StandardSqmSelectTranslator; +import org.hibernate.query.sqm.tree.select.SqmSelectStatement; +import org.hibernate.sql.ast.tree.from.CompositeTableGroup; +import org.hibernate.sql.ast.tree.from.FromClause; +import org.hibernate.sql.ast.tree.from.StandardTableGroup; +import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.sql.ast.tree.from.TableGroupJoin; +import org.hibernate.sql.ast.tree.select.SelectStatement; +import org.hibernate.sql.results.graph.DomainResult; +import org.hibernate.sql.results.graph.Fetch; +import org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch; +import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableFetchImpl; +import org.hibernate.sql.results.graph.entity.EntityFetch; +import org.hibernate.sql.results.graph.entity.EntityResult; +import org.hibernate.sql.results.graph.entity.internal.EntityFetchDelayedImpl; +import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl; + +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.Test; +import org.junit.platform.commons.util.CollectionUtils; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hibernate.testing.hamcrest.AssignableMatcher.assignableTo; +import static org.hibernate.testing.hamcrest.CollectionMatchers.hasSize; +import static org.hibernate.testing.hamcrest.CollectionMatchers.isEmpty; +import static org.junit.Assert.assertThat; + /** * @author Nathan Xu */ +@DomainModel( + annotatedClasses = { + CriteriaEntityGraphTest.Cat.class, + CriteriaEntityGraphTest.Person.class, + CriteriaEntityGraphTest.Country.class, + CriteriaEntityGraphTest.Dog.class, + CriteriaEntityGraphTest.ExpressCompany.class + } +) +@SessionFactory +@TestForIssue( jiraKey = "HHH-13756" ) public class CriteriaEntityGraphTest { + + @Test + void testBasicFetchSemantics(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, eg, GraphSemantic.FETCH, session ); + + // Check the from-clause + assertEmptyJoinedGroup( sqlAst ); + + // Check the domain-result graph + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, + entityFetch -> assertThat( entityFetch, instanceOf( EntityFetchDelayedImpl.class ) ) + ); + } + ); + } + + @Test + void testFetchSemanticsWithSubgraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ); + + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, eg, GraphSemantic.FETCH, session ); + + // Check the from-clause + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); + + // Check the domain-result graph + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> {} ); + } + ); + } + + @Test + void testFetchSemanticsWithDeepSubgraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ).addSubgraph( "company", ExpressCompany.class ); + + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, eg, GraphSemantic.FETCH, session ); + + // Check the from-clause + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, tableGroup -> { + Set tableGroupJoins = tableGroup.getTableGroupJoins(); + Map> tableGroupByName = tableGroupJoins.stream() + .map( TableGroupJoin::getJoinedGroup ) + .collect( Collectors.toMap( + tg -> tg.getModelPart().getPartName(), + TableGroup::getClass + ) ); + Map > expectedTableGroupByName = new HashMap<>(); + expectedTableGroupByName.put( "homeAddress", CompositeTableGroup.class ); + expectedTableGroupByName.put( "company", StandardTableGroup.class ); + assertThat( tableGroupByName, is( expectedTableGroupByName ) ); + } ); + + // Check the domain-result graph + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { + assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); + final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); + final Map> fetchClassByAttributeName = ownerEntityResult.getFetches() + .stream().collect( Collectors.toMap( + fetch -> fetch.getFetchedMapping().getPartName(), + Fetch::getClass + ) ); + final Map> expectedFetchClassByAttributeName = new HashMap<>(); + expectedFetchClassByAttributeName.put( "homeAddress", EmbeddableFetchImpl.class ); + expectedFetchClassByAttributeName.put( "pets", DelayedCollectionFetch.class ); + expectedFetchClassByAttributeName.put( "company", EntityFetchJoinedImpl.class ); + assertThat( fetchClassByAttributeName, is( expectedFetchClassByAttributeName ) ); + + final Fetch companyFetch = ownerEntityResult.findFetch( "company" ); + assertThat( companyFetch, notNullValue() ); + + final EntityResult companyEntityResult = ( (EntityFetchJoinedImpl) companyFetch).getEntityResult(); + assertThat( companyEntityResult.getFetches(), hasSize( 1 ) ); + + final Fetch shipAddressesFetch = companyEntityResult.getFetches().get( 0 ); + assertThat( shipAddressesFetch.getFetchedMapping().getPartName(), is( "shipAddresses" ) ); + assertThat( shipAddressesFetch, instanceOf( DelayedCollectionFetch.class ) ); + } ); + } + ); + } + + @Test + void testBasicLoadSemantics(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, eg, GraphSemantic.LOAD, session ); + + // Check the from-clause + assertEmptyJoinedGroup( sqlAst ); + + // Check the domain-result graph + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, + entityFetch -> assertThat( entityFetch, instanceOf( EntityFetchDelayedImpl.class ) ) ); + } + ); + } + + @Test + void testLoadLoadPlanBuildingWithSubgraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ); + + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, eg, GraphSemantic.LOAD, session ); + + // Check the from-clause + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); + + // Check the domain-result graph + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { + assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); + final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); + final Map> fetchClassByAttributeName = entityResult.getFetches().stream().collect( Collectors.toMap( + fetch -> fetch.getFetchedMapping().getPartName(), + Fetch::getClass + ) ); + final Map> expectedFetchClassByAttributeName = new HashMap<>(); + expectedFetchClassByAttributeName.put( "pets", DelayedCollectionFetch.class ); + expectedFetchClassByAttributeName.put( "homeAddress", EmbeddableFetchImpl.class ); + expectedFetchClassByAttributeName.put( "company", EntityFetchDelayedImpl.class ); + assertThat( fetchClassByAttributeName, is( expectedFetchClassByAttributeName ) ); + } ); + } + ); + } + + @Test + void testBasicElementCollectionsLoadGraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Dog.class ); + eg.addAttributeNodes( "favorites" ); + + final SelectStatement sqlAst = buildSqlSelectAst( Dog.class, eg, GraphSemantic.LOAD, session ); + + // Check the from-clause + assertPluralAttributeJoinedGroup( sqlAst, "favorites", tableGroup -> {} ); + } + ); + } + + @Test + void testBasicElementCollectionsFetchGraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( Dog.class ); + eg.addAttributeNodes( "favorites" ); + + final SelectStatement sqlAst = buildSqlSelectAst( Dog.class, eg, GraphSemantic.FETCH, session ); + + // Check the from-clause + assertPluralAttributeJoinedGroup( sqlAst, "favorites", tableGroup -> {} ); + } + ); + } + + @Test + void testEmbeddedCollectionLoadGraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( ExpressCompany.class ); + eg.addAttributeNodes( "shipAddresses" ); + + final SelectStatement sqlAst = buildSqlSelectAst( + ExpressCompany.class, + eg, GraphSemantic.LOAD, + session + ); + + // Check the from-clause + assertPluralAttributeJoinedGroup( sqlAst, "shipAddresses", tableGroup -> { + assertThat( tableGroup.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup compositeTableGroup = tableGroup.getTableGroupJoins().iterator().next().getJoinedGroup(); + assertThat( compositeTableGroup, instanceOf( CompositeTableGroup.class ) ); + assertThat( compositeTableGroup.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup countryTableGroup = compositeTableGroup.getTableGroupJoins().iterator().next().getJoinedGroup(); + assertThat( countryTableGroup.getModelPart().getPartName(), is( "country" ) ); + + assertThat( countryTableGroup.getTableGroupJoins(), isEmpty() ); + } ); + + } + ); + } + + @Test + void testEmbeddedCollectionFetchGraph(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + final RootGraphImplementor eg = session.createEntityGraph( ExpressCompany.class ); + eg.addAttributeNodes( "shipAddresses" ); + + final SelectStatement sqlAst = buildSqlSelectAst( + ExpressCompany.class, + eg, GraphSemantic.FETCH, + session + ); + + // Check the from-clause + assertPluralAttributeJoinedGroup( sqlAst, "shipAddresses", tableGroup -> { + assertThat( tableGroup.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup compositeTableGroup = CollectionUtils.getOnlyElement( tableGroup.getTableGroupJoins() ).getJoinedGroup(); + assertThat( compositeTableGroup, instanceOf( CompositeTableGroup.class ) ); + assertThat( compositeTableGroup.getTableGroupJoins(), isEmpty() ); + } ); + + } + ); + } + + // util methods for verifying 'from-clause' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + private void assertEmptyJoinedGroup(SelectStatement sqlAst) { + final FromClause fromClause = sqlAst.getQuerySpec().getFromClause(); + assertThat( fromClause.getRoots(), hasSize( 1 ) ); + + final TableGroup rootTableGroup = fromClause.getRoots().get( 0 ); + assertThat( rootTableGroup.getTableGroupJoins(), isEmpty() ); + } + + private void assertEntityValuedJoinedGroup(SelectStatement sqlAst, String expectedAttributeName, Class expectedEntityJpaClass, Consumer tableGroupConsumer) { + final FromClause fromClause = sqlAst.getQuerySpec().getFromClause(); + assertThat( fromClause.getRoots(), hasSize( 1 ) ); + + final TableGroup rootTableGroup = fromClause.getRoots().get( 0 ); + assertThat( rootTableGroup.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup joinedGroup = rootTableGroup.getTableGroupJoins().iterator().next().getJoinedGroup(); + assertThat( joinedGroup.getModelPart().getPartName(), is( expectedAttributeName ) ); + assertThat( joinedGroup.getModelPart().getJavaTypeDescriptor().getJavaType(), assignableTo( expectedEntityJpaClass ) ); + assertThat( joinedGroup.getModelPart(), instanceOf( EntityValuedModelPart.class ) ); + + tableGroupConsumer.accept( joinedGroup ); + } + + private void assertPluralAttributeJoinedGroup(SelectStatement sqlAst, String expectedPluralAttributeName, Consumer tableGroupConsumer) { + final FromClause fromClause = sqlAst.getQuerySpec().getFromClause(); + assertThat( fromClause.getRoots(), hasSize( 1 ) ); + + final TableGroup root = fromClause.getRoots().get( 0 ); + assertThat( root.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup joinedGroup = root.getTableGroupJoins().iterator().next().getJoinedGroup(); + assertThat( joinedGroup.getModelPart().getPartName(), is( expectedPluralAttributeName ) ); + assertThat( joinedGroup.getModelPart(), instanceOf( PluralAttributeMapping.class ) ); + tableGroupConsumer.accept( joinedGroup ); + } + + private void assertPersonHomeAddressJoinedGroup(TableGroup tableGroup) { + assertThat( tableGroup.getTableGroupJoins(), hasSize( 1 ) ); + + final TableGroup joinedGroup = tableGroup.getTableGroupJoins().iterator().next().getJoinedGroup(); + assertThat( joinedGroup.getModelPart().getPartName(), is( "homeAddress" ) ); + assertThat( joinedGroup.getModelPart(), instanceOf( EmbeddedAttributeMapping.class ) ); + assertThat( joinedGroup, instanceOf( CompositeTableGroup.class ) ); + } + + // util methods for verifying 'domain-result' graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + private void assertDomainResult(SelectStatement sqlAst, + Class expectedEntityJpaClass, + String expectedAttributeName, + Class expectedAttributeEntityJpaClass, + Consumer entityFetchConsumer) { + assertThat( sqlAst.getDomainResultDescriptors(), hasSize( 1 ) ); + + final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get( 0 ); + assertThat( domainResult, instanceOf( EntityResult.class ) ); + + final EntityResult entityResult = (EntityResult) domainResult; + assertThat( entityResult.getReferencedModePart().getJavaTypeDescriptor().getJavaType(), assignableTo( expectedEntityJpaClass ) ); + assertThat( entityResult.getFetches(), hasSize( 1 ) ); + + final Fetch fetch = entityResult.getFetches().get( 0 ); + assertThat( fetch, instanceOf( EntityFetch.class ) ); + + final EntityFetch entityFetch = (EntityFetch) fetch; + assertThat( entityFetch.getFetchedMapping().getFetchableName(), is( expectedAttributeName ) ); + assertThat( entityFetch.getReferencedModePart().getJavaTypeDescriptor().getJavaType(), assignableTo( expectedAttributeEntityJpaClass ) ); + + entityFetchConsumer.accept( entityFetch ); + } + + private SelectStatement buildSqlSelectAst( + Class entityType, + RootGraphImplementor entityGraph, + GraphSemantic mode, + SessionImplementor session) { + + final LoadQueryInfluencers loadQueryInfluencers = new LoadQueryInfluencers( session.getSessionFactory() ); + final EffectiveEntityGraph effectiveEntityGraph = loadQueryInfluencers.getEffectiveEntityGraph(); + effectiveEntityGraph.applyGraph( entityGraph, mode ); + + final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery( entityType ); + criteriaQuery.select( criteriaQuery.from( entityType ) ); + + final QueryImplementor query = session.createQuery( criteriaQuery ); + final HqlQueryImplementor hqlQuery = (HqlQueryImplementor) query; + + final SqmSelectStatement sqmStatement = (SqmSelectStatement) hqlQuery.getSqmStatement(); + + final StandardSqmSelectTranslator sqmConverter = new StandardSqmSelectTranslator( + hqlQuery.getQueryOptions(), + ( (QuerySqmImpl) hqlQuery ).getDomainParameterXref(), + query.getParameterBindings(), + loadQueryInfluencers, + session.getSessionFactory() + ); + + final SqmSelectTranslation sqmInterpretation = sqmConverter.translate( sqmStatement ); + return sqmInterpretation.getSqlAst(); + } + + @Entity(name = "Dog") + public static class Dog { + @Id + String name; + + @ElementCollection + Set favorites; + } + + @Entity(name = "Cat") + public static class Cat { + @Id + String name; + + @ManyToOne(fetch = FetchType.LAZY) + Person owner; + } + + @Entity(name = "Person") + public static class Person { + @Id + String name; + + @OneToMany(mappedBy = "owner") + Set pets; + + @Embedded + Address homeAddress; + + @ManyToOne(fetch = FetchType.LAZY) + ExpressCompany company; + } + + @Embeddable + public static class Address { + @ManyToOne + Country country; + } + + @Entity(name = "ExpressCompany") + public static class ExpressCompany { + @Id + String name; + + @ElementCollection + Set
shipAddresses; + } + + @Entity(name = "Country") + public static class Country { + @Id + String name; + } } + diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/entitygraph/HqlEntityGraphTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/entitygraph/HqlEntityGraphTest.java index eac3ccfd3e81..f6229f98ce85 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/entitygraph/HqlEntityGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/entitygraph/HqlEntityGraphTest.java @@ -84,15 +84,15 @@ public class HqlEntityGraphTest { void testBasicFetchSemantics(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Cat.class ); + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Cat.class, "select c from Cat c", eg, GraphSemantic.FETCH, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, "select c from Cat c", eg, GraphSemantic.FETCH, session ); // Check the from-clause assertEmptyJoinedGroup( sqlAst ); // Check the domain-result graph - assertDomainResult( sqlAst, HqlEntityGraphTest.Cat.class, "owner", Person.class, + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> assertThat( entityFetch, instanceOf( EntityFetchDelayedImpl.class ) ) ); } @@ -103,16 +103,16 @@ void testBasicFetchSemantics(SessionFactoryScope scope) { void testFetchSemanticsWithSubgraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Cat.class ); - eg.addSubgraph( "owner", HqlEntityGraphTest.Person.class ); + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Cat.class, "select c from Cat as c", eg, GraphSemantic.FETCH, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, "select c from Cat as c", eg, GraphSemantic.FETCH, session ); // Check the from-clause - assertEntityValuedJoinedGroup( sqlAst, "owner", HqlEntityGraphTest.Person.class, this::assertPersonHomeAddressJoinedGroup ); + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); // Check the domain-result graph - assertDomainResult( sqlAst, HqlEntityGraphTest.Cat.class, "owner", HqlEntityGraphTest.Person.class, entityFetch -> {} ); + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> {} ); } ); } @@ -121,13 +121,13 @@ void testFetchSemanticsWithSubgraph(SessionFactoryScope scope) { void testFetchSemanticsWithDeepSubgraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Cat.class ); - eg.addSubgraph( "owner", HqlEntityGraphTest.Person.class ).addSubgraph( "company", HqlEntityGraphTest.ExpressCompany.class ); + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ).addSubgraph( "company", ExpressCompany.class ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Cat.class, "select c from Cat as c", eg, GraphSemantic.FETCH, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, "select c from Cat as c", eg, GraphSemantic.FETCH, session ); // Check the from-clause - assertEntityValuedJoinedGroup( sqlAst, "owner", HqlEntityGraphTest.Person.class, tableGroup -> { + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, tableGroup -> { Set tableGroupJoins = tableGroup.getTableGroupJoins(); Map> tableGroupByName = tableGroupJoins.stream() .map( TableGroupJoin::getJoinedGroup ) @@ -142,7 +142,7 @@ void testFetchSemanticsWithDeepSubgraph(SessionFactoryScope scope) { } ); // Check the domain-result graph - assertDomainResult( sqlAst, HqlEntityGraphTest.Cat.class, "owner", HqlEntityGraphTest.Person.class, entityFetch -> { + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); final EntityResult ownerEntityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final Map> fetchClassByAttributeName = ownerEntityResult.getFetches() @@ -174,15 +174,15 @@ void testFetchSemanticsWithDeepSubgraph(SessionFactoryScope scope) { void testBasicLoadSemantics(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Cat.class ); + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Cat.class, "select c from Cat as c", eg, GraphSemantic.LOAD, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, "select c from Cat as c", eg, GraphSemantic.LOAD, session ); // Check the from-clause assertEmptyJoinedGroup( sqlAst ); // Check the domain-result graph - assertDomainResult( sqlAst, HqlEntityGraphTest.Cat.class, "owner", HqlEntityGraphTest.Person.class, + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> assertThat( entityFetch, instanceOf( EntityFetchDelayedImpl.class ) ) ); } ); @@ -192,16 +192,16 @@ void testBasicLoadSemantics(SessionFactoryScope scope) { void testLoadLoadPlanBuildingWithSubgraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Cat.class ); - eg.addSubgraph( "owner", HqlEntityGraphTest.Person.class ); + final RootGraphImplementor eg = session.createEntityGraph( Cat.class ); + eg.addSubgraph( "owner", Person.class ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Cat.class, "select c from Cat as c", eg, GraphSemantic.LOAD, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Cat.class, "select c from Cat as c", eg, GraphSemantic.LOAD, session ); // Check the from-clause - assertEntityValuedJoinedGroup( sqlAst, "owner", HqlEntityGraphTest.Person.class, this::assertPersonHomeAddressJoinedGroup ); + assertEntityValuedJoinedGroup( sqlAst, "owner", Person.class, this::assertPersonHomeAddressJoinedGroup ); // Check the domain-result graph - assertDomainResult( sqlAst, HqlEntityGraphTest.Cat.class, "owner", HqlEntityGraphTest.Person.class, entityFetch -> { + assertDomainResult( sqlAst, Cat.class, "owner", Person.class, entityFetch -> { assertThat( entityFetch, instanceOf( EntityFetchJoinedImpl.class ) ); final EntityResult entityResult = ( (EntityFetchJoinedImpl) entityFetch ).getEntityResult(); final Map> fetchClassByAttributeName = entityResult.getFetches().stream().collect( Collectors.toMap( @@ -222,10 +222,10 @@ void testLoadLoadPlanBuildingWithSubgraph(SessionFactoryScope scope) { void testBasicElementCollectionsLoadGraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Dog.class ); + final RootGraphImplementor eg = session.createEntityGraph( Dog.class ); eg.addAttributeNodes( "favorites" ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Dog.class, "select d from Dog as d", eg, GraphSemantic.LOAD, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Dog.class, "select d from Dog as d", eg, GraphSemantic.LOAD, session ); // Check the from-clause assertPluralAttributeJoinedGroup( sqlAst, "favorites", tableGroup -> {} ); @@ -237,10 +237,10 @@ void testBasicElementCollectionsLoadGraph(SessionFactoryScope scope) { void testBasicElementCollectionsFetchGraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.Dog.class ); + final RootGraphImplementor eg = session.createEntityGraph( Dog.class ); eg.addAttributeNodes( "favorites" ); - final SelectStatement sqlAst = buildSqlSelectAst( HqlEntityGraphTest.Dog.class, "select d from Dog as d", eg, GraphSemantic.FETCH, session ); + final SelectStatement sqlAst = buildSqlSelectAst( Dog.class, "select d from Dog as d", eg, GraphSemantic.FETCH, session ); // Check the from-clause assertPluralAttributeJoinedGroup( sqlAst, "favorites", tableGroup -> {} ); @@ -252,11 +252,11 @@ void testBasicElementCollectionsFetchGraph(SessionFactoryScope scope) { void testEmbeddedCollectionLoadGraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.ExpressCompany.class ); + final RootGraphImplementor eg = session.createEntityGraph( ExpressCompany.class ); eg.addAttributeNodes( "shipAddresses" ); final SelectStatement sqlAst = buildSqlSelectAst( - HqlEntityGraphTest.ExpressCompany.class, + ExpressCompany.class, "select company from ExpressCompany as company", eg, GraphSemantic.LOAD, session @@ -284,11 +284,11 @@ void testEmbeddedCollectionLoadGraph(SessionFactoryScope scope) { void testEmbeddedCollectionFetchGraph(SessionFactoryScope scope) { scope.inTransaction( session -> { - final RootGraphImplementor eg = session.createEntityGraph( HqlEntityGraphTest.ExpressCompany.class ); + final RootGraphImplementor eg = session.createEntityGraph( ExpressCompany.class ); eg.addAttributeNodes( "shipAddresses" ); final SelectStatement sqlAst = buildSqlSelectAst( - HqlEntityGraphTest.ExpressCompany.class, + ExpressCompany.class, "select company from ExpressCompany as company", eg, GraphSemantic.FETCH, session