简体   繁体   English

grails executeQuery HQL-找不到参数

[英]grails executeQuery HQL - could not locate parameter

I seldom use use executeQuery in querying because sometimes i got this error and i don't know how to fix it, here is my code: 我很少在查询中使用executeexecuteQuery ,因为有时会出现此错误,并且我不知道如何解决它,这是我的代码:

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])            
}

and I got this error message: could not locate named parameter [refDate] i tried to delete the condition where i dont need to compare it to my declared parameter ( and rt.registrant.birthDate>=:refdate",[refDate:refereneceDate] ) and it worked. i really dont know why i am still getting this error, it seems like i declared the parameter correctly, and the passed value parameter is valid because i can see it printed in my terminal. thanks in advance. 并且我收到此错误消息: 找不到命名参数[refDate]我试图删除不需要将其与声明的参数进行比较的条件( 和rt.registrant.birthDate> =:refdate“,[refDate:refereneceDate] ),它确实起作用。我真的不知道为什么我仍然遇到此错误,似乎我正确地声明了该参数,并且传递的值参数是有效的,因为我可以在终端中看到它的打印。

Triple quoted multi-line strings will not work with HQL according the the manual (see the multiline query section). 根据手册,三引号引起来的多行字符串不适用于HQL(请参阅多行查询部分)。 Try using the line continuation character: 尝试使用换行符:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM