1

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

4

1 回答 1

0

根据手册,三引号多行字符串不适用于 HQL (请参阅多行查询部分)。尝试使用行继续符:

executeQuery("select rt.registrant.emailAddress \
from RegistrantTestingCenterExamSchedule as rt \
.... \
or rt.registrant.birthDate >= :refDate", [refDate : referenceDate])
于 2012-08-04T07:01:06.070 回答