java.lang.IllegalArgumentException:org.hibernate.QueryParameterException:找不到命名参数[taskPackageId]

时间:2015-10-21 23:38:33

标签: java hibernate

IF (((SELECT COUNT(*) FROM com.abc.domain.dcm.Program AS p
                    INNER JOIN p.programServiceLevelConfigs AS pslc
                    INNER JOIN pslc.taskPackages AS taskPackages
                    WHERE taskPackages.id = :taskPackageId) > 0) OR
            ((SELECT COUNT(*) from com.abc.domain.dcm.HcsEnrollmentBhpSetup hbs
                    INNER JOIN hbs.taskPackageMap
                    WHERE elements(hbs.taskPackageMap.id) = :taskPackageId) > 0))
        SELECT 1
    ELSE
        SELECT 0

我正在设置查询参数:

query.setParameter("taskPackageId", taskPackageId);

在执行上述HQL查询时,我得到以下异常堆栈跟踪:

java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [taskPackageId]
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:379)
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:72)

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您无法在HQL中使用if...else语句。可以CASE expression帮助您。