Search in sources :

Example 1 with DynamicResultBuilderAttribute

use of org.hibernate.query.results.dynamic.DynamicResultBuilderAttribute in project hibernate-orm by hibernate.

the class Builders method attributeResult.

public static ResultBuilder attributeResult(String columnAlias, String entityName, String attributePath, SessionFactoryImplementor sessionFactory) {
    if (attributePath.contains(".")) {
        throw new NotYetImplementedFor6Exception("Support for defining a NativeQuery attribute result based on a composite path is not yet implemented");
    }
    final RuntimeMetamodels runtimeMetamodels = sessionFactory.getRuntimeMetamodels();
    final String fullEntityName = runtimeMetamodels.getMappingMetamodel().getImportedName(entityName);
    final EntityPersister entityMapping = runtimeMetamodels.getMappingMetamodel().findEntityDescriptor(fullEntityName);
    if (entityMapping == null) {
        throw new IllegalArgumentException("Could not locate entity mapping : " + fullEntityName);
    }
    final AttributeMapping attributeMapping = entityMapping.findAttributeMapping(attributePath);
    if (attributeMapping == null) {
        throw new IllegalArgumentException("Could not locate attribute mapping : " + fullEntityName + "." + attributePath);
    }
    if (attributeMapping instanceof SingularAttributeMapping) {
        final SingularAttributeMapping singularAttributeMapping = (SingularAttributeMapping) attributeMapping;
        return new DynamicResultBuilderAttribute(singularAttributeMapping, columnAlias, fullEntityName, attributePath);
    }
    throw new IllegalArgumentException(String.format(Locale.ROOT, "Specified attribute mapping [%s.%s] not a basic attribute: %s", fullEntityName, attributePath, attributeMapping));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) DynamicResultBuilderAttribute(org.hibernate.query.results.dynamic.DynamicResultBuilderAttribute) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping) AttributeMapping(org.hibernate.metamodel.mapping.AttributeMapping) NotYetImplementedFor6Exception(org.hibernate.NotYetImplementedFor6Exception) RuntimeMetamodels(org.hibernate.metamodel.RuntimeMetamodels) SingularAttributeMapping(org.hibernate.metamodel.mapping.SingularAttributeMapping)

Aggregations

NotYetImplementedFor6Exception (org.hibernate.NotYetImplementedFor6Exception)1 RuntimeMetamodels (org.hibernate.metamodel.RuntimeMetamodels)1 AttributeMapping (org.hibernate.metamodel.mapping.AttributeMapping)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1 SingularAttributeMapping (org.hibernate.metamodel.mapping.SingularAttributeMapping)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 DynamicResultBuilderAttribute (org.hibernate.query.results.dynamic.DynamicResultBuilderAttribute)1