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