异常的原因是什么&org.hibernate.QueryException消息并未设置所有命名参数:'可能是?

时间:2014-08-18 09:27:59

标签: java hibernate grails

所以我试图在grails中执行以下查询

User user = springSecurityService.currentUser
def approverGroupList = approverGroupService.getApproverGroupsByUser(user.id)
return VerificationRequest.executeQuery("select distinct v.fundTransfer from VerificationRequest v where v.fundTransfer.creator.corporateHouse=:corporateHouse and v.verified = false and v.fundTransfer.status ='QUEUED' and v.approverGroup in (:approverGroupList)", [corporateHouse:corporateHouse],[approverGroupList:approverGroupList])

但是我得到以下例外:

/fund-transfer/list-verification-requests
Class
    org.hibernate.QueryException
Message
    Not all named parameters have been set: [approverGroupList] [select distinct v.fundTransfer from VerificationRequest v where v.fundTransfer.creator.corporateHouse=:corporateHouse and v.verified = false and v.fundTransfer.status ='QUEUED' and v.approverGroup in (:approverGroupList)]

另外,corporateHouse是一个传递给执行此查询的方法的对象,它不是null。 可能是什么原因?

P.S。我是grails的新手!

3 个答案:

答案 0 :(得分:4)

Looks like参数应位于一个地图中,如下所示:

[corporateHouse:corporateHouse, approverGroupList:approverGroupList]

答案 1 :(得分:4)

您已将两张地图传递给executeQuery

VerificationRequest.executeQuery("...", [corporateHouse:corporateHouse],[approverGroupList:approverGroupList])

它应该是一个有两个值的地图:

VerificationRequest.executeQuery("...", [corporateHouse:corporateHouse, approverGroupList:approverGroupList])

根据documentation,第二张地图被视为带有其他参数的地图。

答案 2 :(得分:0)

这意味着您尚未在查询中设置所有参数。您错过了一些检查查询执行代码