简体   繁体   中英

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:

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.

Triple quoted multi-line strings will not work with HQL according the the manual (see the multiline query section). Try using the line continuation character:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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