Search in sources :

Example 1 with RootGraphImpl

use of org.hibernate.graph.internal.RootGraphImpl in project hibernate-orm by hibernate.

the class JpaMetamodelImpl method applyNamedEntityGraphs.

@SuppressWarnings("unchecked")
private void applyNamedEntityGraphs(Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
    for (NamedEntityGraphDefinition definition : namedEntityGraphs) {
        log.debugf("Applying named entity graph [name=%s, entity-name=%s, jpa-entity-name=%s]", definition.getRegisteredName(), definition.getEntityName(), definition.getJpaEntityName());
        final EntityDomainType<Object> entityType = entity(definition.getEntityName());
        if (entityType == null) {
            throw new IllegalArgumentException("Attempted to register named entity graph [" + definition.getRegisteredName() + "] for unknown entity [" + definition.getEntityName() + "]");
        }
        final RootGraphImpl<Object> entityGraph = new RootGraphImpl<>(definition.getRegisteredName(), entityType, this);
        final NamedEntityGraph namedEntityGraph = definition.getAnnotation();
        if (namedEntityGraph.includeAllAttributes()) {
            for (Attribute<? super Object, ?> attribute : entityType.getAttributes()) {
                entityGraph.addAttributeNodes(attribute);
            }
        }
        if (namedEntityGraph.attributeNodes() != null) {
            applyNamedAttributeNodes(namedEntityGraph.attributeNodes(), namedEntityGraph, entityGraph);
        }
        entityGraphMap.put(definition.getRegisteredName(), entityGraph);
    }
}
Also used : NamedEntityGraphDefinition(org.hibernate.cfg.annotations.NamedEntityGraphDefinition) NamedEntityGraph(jakarta.persistence.NamedEntityGraph) RootGraphImpl(org.hibernate.graph.internal.RootGraphImpl)

Example 2 with RootGraphImpl

use of org.hibernate.graph.internal.RootGraphImpl in project hibernate-orm by hibernate.

the class AbstractCommonQueryContract method applyGraph.

protected void applyGraph(String graphString, GraphSemantic graphSemantic) {
    final int separatorPosition = graphString.indexOf('(');
    final int terminatorPosition = graphString.lastIndexOf(')');
    if (separatorPosition < 0 || terminatorPosition < 0) {
        throw new IllegalArgumentException(String.format(ROOT, "Invalid entity-graph definition `%s`; expected form `${EntityName}( ${property1} ... )", graphString));
    }
    final RuntimeMetamodels runtimeMetamodels = getSession().getFactory().getRuntimeMetamodels();
    final JpaMetamodel jpaMetamodel = runtimeMetamodels.getJpaMetamodel();
    final String entityName = runtimeMetamodels.getImportedName(graphString.substring(0, separatorPosition).trim());
    final String graphNodes = graphString.substring(separatorPosition + 1, terminatorPosition);
    final RootGraphImpl<?> rootGraph = new RootGraphImpl<>(null, jpaMetamodel.entity(entityName), jpaMetamodel);
    GraphParser.parseInto((EntityGraph<?>) rootGraph, graphNodes, getSession().getSessionFactory());
    applyGraph(rootGraph, graphSemantic);
}
Also used : RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) RootGraphImpl(org.hibernate.graph.internal.RootGraphImpl) JpaMetamodel(org.hibernate.metamodel.model.domain.JpaMetamodel)

Aggregations

RootGraphImpl (org.hibernate.graph.internal.RootGraphImpl)2 NamedEntityGraph (jakarta.persistence.NamedEntityGraph)1 NamedEntityGraphDefinition (org.hibernate.cfg.annotations.NamedEntityGraphDefinition)1 RuntimeMetamodels (org.hibernate.metamodel.RuntimeMetamodels)1 JpaMetamodel (org.hibernate.metamodel.model.domain.JpaMetamodel)1