Skip to content

Commit c9226a3

Browse files
GRAILS-6140 - more reliable mechanism for determining if a method call made inside of a named query is a call to another named query
1 parent f69bcde commit c9226a3

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/java/org/codehaus/groovy/grails/orm/hibernate/cfg/HibernateNamedQueriesBuilder.groovy

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.codehaus.groovy.grails.orm.hibernate.cfg
1717

18+
import java.lang.reflect.Modifier
1819
import org.codehaus.groovy.grails.orm.hibernate.metaclass.*
1920
import org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport
2021
import org.hibernate.criterion.CriteriaSpecification
@@ -193,14 +194,18 @@ class NamedCriteriaProxy {
193194
def nextInChain = domainClass.metaClass.getMetaProperty(methodName).getProperty(domainClass)
194195
nextInChain.previousInChain = this
195196
return nextInChain(args)
196-
} else if (domainClass.metaClass.getMetaProperty(methodName) &&
197-
!Collection.isAssignableFrom(domainClass.metaClass.getMetaProperty(methodName).type)) {
198-
def nestedCriteria = domainClass.metaClass.getMetaProperty(methodName).getProperty(domainClass).criteriaClosure.clone()
199-
nestedCriteria.delegate = queryBuilder
200-
nestedCriteria(*args)
201197
} else {
202-
queryBuilder."${methodName}"(*args)
198+
def metaProperty = domainClass.metaClass.getMetaProperty(methodName)
199+
if(metaProperty && Modifier.isStatic(metaProperty.modifiers)) {
200+
def staticProperty = metaProperty.getProperty(domainClass)
201+
if(staticProperty instanceof NamedCriteriaProxy) {
202+
def nestedCriteria = staticProperty.criteriaClosure.clone()
203+
nestedCriteria.delegate = queryBuilder
204+
return nestedCriteria(*args)
205+
}
206+
}
203207
}
208+
queryBuilder."${methodName}"(*args)
204209
}
205210

206211
private getPreparedCriteriaClosure(additionalCriteriaClosure = null) {

0 commit comments

Comments
 (0)