【问题标题】:grails executeQuery HQL - could not locate parametergrails executeQuery HQL - 找不到参数
【发布时间】:2012-07-30 03:48:04
【问题描述】:

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

【问题讨论】:

  • 应该可以。如果添加一个空格“>= :refDate”会怎样?

标签: hibernate grails hql grails-orm


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    相关资源
    最近更新 更多