use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.
the class CriteriaEntityGraphTest method testSemanticsWithSubgraph.
@ParameterizedTest
@EnumSource(GraphSemantic.class)
void testSemanticsWithSubgraph(GraphSemantic graphSemantic) {
scope.inTransaction(session -> {
final RootGraphImplementor<Cat> eg = session.createEntityGraph(Cat.class);
eg.addSubgraph("owner", Person.class);
final SelectStatement sqlAst = buildSqlSelectAst(Cat.class, eg, graphSemantic, 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 -> {
if (graphSemantic == GraphSemantic.LOAD) {
assertThat(entityFetch, instanceOf(EntityFetchJoinedImpl.class));
final EntityResult entityResult = ((EntityFetchJoinedImpl) entityFetch).getEntityResult();
final Map<String, Class<? extends Fetch>> fetchClassByAttributeName = entityResult.getFetches().stream().collect(Collectors.toMap(fetch -> fetch.getFetchedMapping().getPartName(), Fetch::getClass));
final Map<String, Class<? extends Fetch>> expectedFetchClassByAttributeName = new HashMap<>();
expectedFetchClassByAttributeName.put("pets", DelayedCollectionFetch.class);
expectedFetchClassByAttributeName.put("homeAddress", EmbeddableFetchImpl.class);
expectedFetchClassByAttributeName.put("company", EntityDelayedFetchImpl.class);
assertThat(fetchClassByAttributeName, is(expectedFetchClassByAttributeName));
}
});
});
}
use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.
the class CriteriaEntityGraphTest method assertDomainResult.
// util methods for verifying 'domain-result' graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void assertDomainResult(SelectStatement sqlAst, Class<?> expectedEntityJpaClass, String expectedAttributeName, Class<?> expectedAttributeEntityJpaClass, Consumer<EntityFetch> 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().getJavaType().getJavaTypeClass(), 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().getJavaType().getJavaTypeClass(), assignableTo(expectedAttributeEntityJpaClass));
entityFetchConsumer.accept(entityFetch);
}
use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.
the class HqlEntityGraphTest method assertDomainResult.
// util methods for verifying 'domain-result' graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void assertDomainResult(SelectStatement sqlAst, Class<?> expectedEntityJpaClass, String expectedAttributeName, Class<?> expectedAttributeEntityJpaClass, Consumer<EntityFetch> 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().getJavaType().getJavaTypeClass(), 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().getJavaType().getJavaTypeClass(), assignableTo(expectedAttributeEntityJpaClass));
entityFetchConsumer.accept(entityFetch);
}
use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.
the class EntityGraphLoadPlanBuilderTest method assertDomainResult.
// util methods for verifying 'domain-result' graph ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private void assertDomainResult(SelectStatement sqlAst, Class<?> expectedEntityJpaClass, String expectedAttributeName, Class<?> expectedAttributeEntityJpaClass, Consumer<EntityFetch> 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().getJavaType().getJavaTypeClass(), 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().getJavaType().getJavaTypeClass(), assignableTo(expectedAttributeEntityJpaClass));
entityFetchConsumer.accept(entityFetch);
}
use of org.hibernate.sql.results.graph.entity.EntityResult in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testSimpleBuild.
@Test
public void testSimpleBuild(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister entityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Message.class);
final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>(entityDescriptor, sessionFactory);
final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(LockOptions.READ, LoadQueryInfluencers.NONE, sessionFactory);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect().getJdbcValuesMappingProducer().resolve(null, sessionFactory).getDomainResults();
assertThat(domainResults).hasSize(1);
final DomainResult<?> domainResult = domainResults.get(0);
assertThat(domainResult).isInstanceOf(EntityResult.class);
final EntityResult entityResult = (EntityResult) domainResult;
assertThat(entityResult.getFetches()).hasSize(2);
final Fetch txtFetch = entityResult.getFetches().get(0);
assertThat(txtFetch).isNotNull();
assertThat(txtFetch.getFetchedMapping().getFetchableName()).isEqualTo("msgTxt");
assertThat(txtFetch.getTiming()).isEqualTo(FetchTiming.IMMEDIATE);
final Fetch posterFetch = entityResult.getFetches().get(1);
assertThat(posterFetch).isNotNull();
assertThat(posterFetch.getFetchedMapping().getFetchableName()).isEqualTo("poster");
assertThat(posterFetch.getTiming()).isEqualTo(FetchTiming.DELAYED);
}
Aggregations