0

Wondering why the "where" query bails out in the last example of the following. There is no "where" clause to the where query in case #5 - all Assignments are listed instead of just one. I am executing this in the Grails console, Grails 3.2.5.

import org.grails.compiler.injection.GrailsAwareClassLoader

def domainName = "Assignment"
def domainPathName = "somepath.$domainName"

def domainClass = new GrailsAwareClassLoader().loadClass(domainPathName)

println "1 -----------"
def c = domainClass.createCriteria()
println c.list { 
    eq "id", 9361L
}

println "2 -----------"
def wc = domainClass.withCriteria() {
    eq "id", 9361L
}
println wc.toList()

println "3 -----------"
def d = new DetachedCriteria(domainClass).build {
    eq "id", 9361L
}
println d.list() 

println "4 -----------"
def wa = Assignment.where {
 id == 9361L
}
println wa.list()

println "5 -----------"
def w = domainClass.where {
 id == 9361L
}
println w.list()
Jay
  • 173
  • 10
  • What's the error? Does number 3 or 4 work? You are calling DetachedCriteria & Assignment without importing them? – Mike W Jul 11 '17 at 10:17
  • Oh, they get imported. I omitted DetachedCriteria in this listing, and the console automatically imports the Assignment domain class. All examples produce the expected one-row result except for the last example. – Jay Jul 11 '17 at 11:02

0 Answers0