} else {
((DirectCollectionMapping) mapping).addAscendingOrdering();
}
} else {
// Validate the order by reference.
MappingAccessor referenceAccessor = referenceDescriptor.getMappingAccessor(propertyOrFieldName);
if (referenceAccessor == null) {
throw ValidationException.invalidOrderByValue(propertyOrFieldName, referenceDescriptor.getJavaClass(), getAccessibleObjectName(), javaClass);
}
String attributeName = referenceAccessor.getAttributeName();
if (referenceAccessor.isEmbedded()) {
for (String orderByAttributeName : referenceDescriptor.getOrderByAttributeNames()) {
mapping.addAggregateOrderBy(propertyOrFieldName, orderByAttributeName, ordering.equals(DESCENDING));
}
} else if (referenceAccessor.getClassAccessor().isEmbeddableAccessor()) {
// We have a specific order by from an embeddable, we need to rip off
// the last bit of a dot notation if specified and pass in the chained
// string names of the nested embeddables only.
String embeddableChain = "";
if (propertyOrFieldName.contains(".")) {