java – Spring hibernate模板列表作为参数

前端之家收集整理的这篇文章主要介绍了java – Spring hibernate模板列表作为参数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试执行此查询
码:

this.getHibernateTemplate()
      find("select distinct ci.customer " +
             "from CustomerInvoice ci " +
              "where ci.id in (?) ",ids);

将id作为List,id的类型为Long

执行时我得到例外

码:

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Long
 at org.hibernate.type.LongType.set(LongType.java:42)
 at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
 at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
 at org.hibernate.param.PositionalParameterSpecification.bind(PositionalParameterSpecification.java:39)
 at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:491)
 at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
 at org.hibernate.loader.Loader.doQuery(Loader.java:673)
 at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
 at org.hibernate.loader.Loader.doList(Loader.java:2220)
 at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
 at org.hibernate.loader.Loader.list(Loader.java:2099)
 at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
 at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
 at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
 at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
 at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
 at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:849)
 at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
 at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:840)
 at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:836)
 at
最佳答案
除了mR_fr0g的答案之外,这个还有效:

this.getHibernateTemplate() 
      findByNamedParam("select distinct ci.customer " + 
             "from CustomerInvoice ci " + 
              "where ci.id in (:ids) ","ids",ids); 
原文链接:https://www.f2er.com/spring/432025.html

猜你在找的Spring相关文章