Search in sources :

Example 16 with EntityResult

use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.

the class MappedFetchTests method baseline.

@Test
public void baseline(SessionFactoryScope scope) {
    final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
    final MappingMetamodel domainModel = sessionFactory.getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister rootEntityDescriptor = domainModel.getEntityDescriptor(RootEntity.class);
    final SelectStatement sqlAst = LoaderSelectBuilder.createSelect(rootEntityDescriptor, null, rootEntityDescriptor.getIdentifierMapping(), null, 1, LoadQueryInfluencers.NONE, LockOptions.NONE, jdbcParameter -> {
    }, sessionFactory);
    assertThat(sqlAst.getDomainResultDescriptors().size(), is(1));
    final DomainResult domainResult = sqlAst.getDomainResultDescriptors().get(0);
    assertThat(domainResult, instanceOf(EntityResult.class));
    final EntityResult entityResult = (EntityResult) domainResult;
    final List<Fetch> fetches = entityResult.getFetches();
    // name + both lists
    assertThat(fetches.size(), is(3));
    // order is alphabetical...
    final Fetch nameFetch = fetches.get(0);
    assertThat(nameFetch.getFetchedMapping().getFetchableName(), is("name"));
    assertThat(nameFetch, instanceOf(BasicFetch.class));
    final Fetch nickNamesFetch = fetches.get(1);
    assertThat(nickNamesFetch.getFetchedMapping().getFetchableName(), is("nickNames"));
    assertThat(nickNamesFetch, instanceOf(EagerCollectionFetch.class));
    final Fetch simpleEntitiesFetch = fetches.get(2);
    assertThat(simpleEntitiesFetch.getFetchedMapping().getFetchableName(), is("simpleEntities"));
    assertThat(simpleEntitiesFetch, instanceOf(DelayedCollectionFetch.class));
    final QuerySpec querySpec = sqlAst.getQuerySpec();
    final TableGroup tableGroup = querySpec.getFromClause().getRoots().get(0);
    assertThat(tableGroup.getModelPart(), is(rootEntityDescriptor));
    assertThat(tableGroup.getTableGroupJoins().size(), is(1));
    final TableGroupJoin collectionJoin = tableGroup.getTableGroupJoins().iterator().next();
    assertThat(collectionJoin.getJoinedGroup().getModelPart(), is(nickNamesFetch.getFetchedMapping()));
    assertThat(collectionJoin.getPredicate(), notNullValue());
    assertThat(collectionJoin.getPredicate(), instanceOf(ComparisonPredicate.class));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) DomainResult(org.hibernate.sql.results.graph.DomainResult) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult) ComparisonPredicate(org.hibernate.sql.ast.tree.predicate.ComparisonPredicate) DelayedCollectionFetch(org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch) BasicFetch(org.hibernate.sql.results.graph.basic.BasicFetch) Fetch(org.hibernate.sql.results.graph.Fetch) EagerCollectionFetch(org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch) TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) DelayedCollectionFetch(org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch) MappingMetamodel(org.hibernate.metamodel.MappingMetamodel) QuerySpec(org.hibernate.sql.ast.tree.select.QuerySpec) EagerCollectionFetch(org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch) Test(org.junit.jupiter.api.Test)

Aggregations

EntityResult (org.hibernate.sql.results.graph.entity.EntityResult)16 DomainResult (org.hibernate.sql.results.graph.DomainResult)14 Fetch (org.hibernate.sql.results.graph.Fetch)13 DelayedCollectionFetch (org.hibernate.sql.results.graph.collection.internal.DelayedCollectionFetch)10 EntityPersister (org.hibernate.persister.entity.EntityPersister)9 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)9 EntityFetch (org.hibernate.sql.results.graph.entity.EntityFetch)9 Test (org.junit.jupiter.api.Test)9 HashMap (java.util.HashMap)7 LoadQueryInfluencers (org.hibernate.engine.spi.LoadQueryInfluencers)7 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)7 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)7 ElementCollection (jakarta.persistence.ElementCollection)6 Embeddable (jakarta.persistence.Embeddable)6 Embedded (jakarta.persistence.Embedded)6 Entity (jakarta.persistence.Entity)6 FetchType (jakarta.persistence.FetchType)6 Id (jakarta.persistence.Id)6 ManyToOne (jakarta.persistence.ManyToOne)6 OneToMany (jakarta.persistence.OneToMany)6