JPA / Hibernate:IN?1的Collection参数导致“没有为参数1指定值”

时间:2013-02-18 06:05:48

标签: hibernate jpa jdbc parameters

我有一个JPQL查询

SELECT wu.tags, 
  (IF('tag2' IN wu.tags, 1,0) + IF('tag1' IN wu.tags, 1,0) +  0) AS score
FROM WorkUnit wu WHERE wu.tags IN ?1

使用如下例外。

发生了什么事?我应该如何通过收藏? 看起来像Hibernate的错误,因为它在JDBC级别搞砸了。

    String jpql =
        "SELECT wu.tags, (" + sb.toString() + " 0) AS score "
        + "  FROM WorkUnit wu WHERE wu.tags IN ?1";
    return em.createQuery( jpql )
            .setParameter(1, wu.getTags())
            //.setMaxResults(maxResults)
            .getResultList();

wu.getTags()返回Set<WorkTag>

但是这引发了:

java.sql.SQLException: No value specified for parameter 1
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
     at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2611)
     at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2586)
     at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2510)
     at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2259)
     at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
     at java.lang.reflect.Method.invoke(Method.java:601)
     at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
     at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
     at $Proxy72.executeQuery(Unknown Source)
     at org.hibernate.loader.Loader.getResultSet(Loader.java:1897)
     at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1698)
     at org.hibernate.loader.Loader.doQuery(Loader.java:832)
     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
     at org.hibernate.loader.Loader.doList(Loader.java:2382)
     at org.hibernate.loader.Loader.doList(Loader.java:2368)
     at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2198)
     at org.hibernate.loader.Loader.list(Loader.java:2193)
     at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:470)
     at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:355)
     at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
     at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1248)
     at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
     at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:257)
     at org.jboss.essc.web.dao.WorkDao.getWorkUnitsSimilarTo(WorkDao.java:89)

1 个答案:

答案 0 :(得分:1)