Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 3a9d674

Browse files
committed
Merge branch 'sbearcsiro-bugfix/594' into 7.3.x
2 parents 2e2fd44 + 97a06bf commit 3a9d674

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

grails-datastore-gorm-hibernate5/src/main/groovy/org/grails/orm/hibernate/query/GrailsHibernateQueryUtils.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.grails.orm.hibernate.query;
22

3+
import org.grails.datastore.mapping.config.Property;
34
import org.grails.datastore.mapping.reflect.ClassUtils;
45
import org.grails.orm.hibernate.cfg.AbstractGrailsDomainBinder;
56
import org.grails.orm.hibernate.cfg.Mapping;
@@ -272,21 +273,22 @@ private static void addOrderPossiblyNested(CriteriaQuery query,
272273
String sort,
273274
String order,
274275
boolean ignoreCase) {
275-
if (ignoreCase && entity.getPropertyByName(sort).getType() != String.class) {
276-
ignoreCase = false;
277-
}
278276
int firstDotPos = sort.indexOf(".");
279277
if (firstDotPos == -1) {
278+
final PersistentProperty<? extends Property> property = entity.getPropertyByName(sort);
279+
ignoreCase = isIgnoreCaseProperty(ignoreCase, property);
280280
addOrder(entity, query, queryRoot, criteriaBuilder, sort, order, ignoreCase);
281281
} else { // nested property
282282
String sortHead = sort.substring(0, firstDotPos);
283283
String sortTail = sort.substring(firstDotPos + 1);
284-
PersistentProperty property = entity.getPropertyByName(sortHead);
284+
final PersistentProperty<? extends Property> property = entity.getPropertyByName(sortHead);
285285
if (property instanceof Embedded) {
286286
// embedded objects cannot reference entities (at time of writing), so no more recursion needed
287+
final PersistentProperty<? extends Property> associatedProperty = ((Embedded<?>) property).getAssociatedEntity().getPropertyByName(sortTail);
288+
ignoreCase = isIgnoreCaseProperty(ignoreCase, associatedProperty);
287289
addOrder(entity, query, queryRoot, criteriaBuilder, sort, order, ignoreCase);
288290
} else if (property instanceof Association) {
289-
Association a = (Association) property;
291+
final Association<? extends Property> a = (Association<? extends Property>) property;
290292
final Join join = queryRoot.join(sortHead);
291293
PersistentEntity associatedEntity = a.getAssociatedEntity();
292294
Class<?> propertyTargetClass = associatedEntity.getJavaClass();
@@ -295,6 +297,13 @@ private static void addOrderPossiblyNested(CriteriaQuery query,
295297
}
296298
}
297299

300+
private static boolean isIgnoreCaseProperty(boolean ignoreCase, PersistentProperty<? extends Property> persistentProperty) {
301+
if (ignoreCase && persistentProperty != null && persistentProperty.getType() != String.class) {
302+
ignoreCase = false;
303+
}
304+
return ignoreCase;
305+
}
306+
298307
/**
299308
* Add order directly to criteria.
300309
*/

0 commit comments

Comments
 (0)