无法找到命名参数:使用setParameterList

时间:2016-06-23 08:03:37

标签: sql hibernate

我收到以下错误:

org.hibernate.QueryParameterException: could not locate named parameter [projects]
    at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterDescriptor(ParameterMetadata.java:148)
    at org.hibernate.engine.query.spi.ParameterMetadata.getNamedParameterExpectedType(ParameterMetadata.java:165)
    at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:523)
    at org.hibernate.internal.AbstractQueryImpl.setParameterList(AbstractQueryImpl.java:892)
    at com.pepsico.trackwise.sqa.job.ActivityProcessor.execute(ActivityProcessor.java:117)
    at org.quartz.core.JobRunShell.run(JobRunShell.java:207)
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:560)

这是我的查询:

<sql-query name="findRecordsByPerson">
    <return-scalar column="prId" type="java.lang.Integer"/>

    SELECT pr.id AS prId
    FROM pr
    INNER JOIN project pj ON pr.project_id=pj.id
    INNER JOIN pr_addtl_data PAD ON pr.id=PAD.pr_id
    INNER JOIN data_fields df ON df.id=PAD.data_field_id
    WHERE df.field_class IN (7, 16)
      AND PAD.n_value = :pid
      AND pj.name IN (:projects)
    UNION
    SELECT pr.id AS prId
    FROM pr
    INNER JOIN project pj ON pr.project_id=pj.id
    WHERE originator_rel_id=:pid
      AND pj.name IN (:projects)

</sql-query>  

这是我的代码:

List prList = db.getNamedQuery("findRecordsByPerson")
                                .setInteger("pid", pid)
                                .setParameterList("projects", Arrays.asList(new String[]{Constants.PROJECT_SUPPLIER_SITE, Constants.PROJECT_SUPPLIER_SITE_APPROVAL,
                                        Constants.PROJECT_SUPPLIER_SITE_AUDIT, Constants.PROJECT_SUPPLIER_SITE_MATERIAL}))
                                .list();

我已在此论坛中查看了所有可用的答案。从语法上来说,我发现我的代码是正确的,不知道这里缺少什么。请帮忙。

0 个答案:

没有答案