11package org .grails .orm .hibernate .query ;
22
3+ import org .grails .datastore .mapping .config .Property ;
34import org .grails .datastore .mapping .reflect .ClassUtils ;
45import org .grails .orm .hibernate .cfg .AbstractGrailsDomainBinder ;
56import 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