grails executeQuery HQL - 找不到参数

时间:2012-08-01 09:07:15

标签: hibernate grails hql gorm

我很少在查询中使用 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] )进行比较,并且它有效。我真的不这样做知道为什么我仍然得到这个错误,似乎我正确地声明了参数,并且传递的值参数是有效的,因为我可以看到它打印在我的终端中。提前感谢。

1 个答案:

答案 0 :(得分:0)

根据manual,三引号多行字符串无法与HQL一起使用(请参阅多行查询部分)。尝试使用行继续符:

executeQuery("select rt.registrant.emailAddress \
from RegistrantTestingCenterExamSchedule as rt \
.... \
or rt.registrant.birthDate >= :refDate", [refDate : referenceDate])