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));
}
Aggregations