use of org.hibernate.graph.GraphSemantic 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.graph.GraphSemantic in project hibernate-reactive by hibernate.
the class ReactiveSessionImpl method reactiveInternalLoad.
@Override
public CompletionStage<Object> reactiveInternalLoad(String entityName, Serializable id, boolean eager, boolean nullable) {
final EffectiveEntityGraph effectiveEntityGraph = getLoadQueryInfluencers().getEffectiveEntityGraph();
final GraphSemantic semantic = effectiveEntityGraph.getSemantic();
final RootGraphImplementor<?> graph = effectiveEntityGraph.getGraph();
boolean clearedEffectiveGraph;
if (semantic == null || graph.appliesTo(entityName)) {
clearedEffectiveGraph = false;
} else {
// log.debug( "Clearing effective entity graph for subsequent-select" );
clearedEffectiveGraph = true;
effectiveEntityGraph.clear();
}
final LoadEventListener.LoadType type;
if (nullable) {
type = LoadEventListener.INTERNAL_LOAD_NULLABLE;
} else {
type = eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
}
threadCheck();
LoadEvent event = new LoadEvent(id, entityName, true, this, getReadOnlyFromLoadQueryInfluencers());
return fireLoadNoChecks(event, type).thenApply(v -> {
Object result = event.getResult();
if (!nullable) {
UnresolvableObjectException.throwIfNull(result, id, entityName);
}
return result;
}).whenComplete((v, x) -> {
if (clearedEffectiveGraph) {
effectiveEntityGraph.applyGraph(graph, semantic);
}
});
}
Aggregations