我很少在查询中使用use executeQuery,因为有时我会收到此错误,并且我不知道如何解决它,这是我的代码:
use(TimeCategory) {
def referenceDate = new Date() - 101.year
println '============================= '+referenceDate
def cancelledSlots = RegistrantTestingCenterExamSchedule.executeQuery("""select rt.registrant.emailAddress from RegistrantTestingCenterExamSchedule as rt
where rt.registrant.firstName in(select i.firstName from Individual i) and rt.registrant.lastName in(select i.lastName from Individual i) and
rt.registrant.middleName in(select i.middleName from Individual i) and rt.registrant.birthDate in(select i.birthDate from Individual i) or
rt.registrant.seniorCitizen = false or rt.registrant.birthDate >=:refDate""",[refDate: referenceDate])
}
我收到此错误消息:
找不到命名参数[refDate]
我试图删除不需要将其与我声明的参数进行比较的条件(和rt.registrant.birthDate> =:refdate“,[refDate:refereneceDate]),它起作用了。我真的不知道为什么我仍然得到这个错误,似乎我正确地声明了该参数,并且传递的值参数是有效的,因为我可以在终端中看到它的打印。
最佳答案
根据manual,三引号引起来的多行字符串不适用于HQL(请参见多行查询部分)。尝试使用换行符:
executeQuery("select rt.registrant.emailAddress \
from RegistrantTestingCenterExamSchedule as rt \
.... \
or rt.registrant.birthDate >= :refDate", [refDate : referenceDate])
关于hibernate - grails executeQuery HQL-找不到参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11756015/