首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate 施用 HQL 查询 使用List 作为查询条件的注意

2012-10-09 
Hibernate 使用 HQL 查询 使用List 作为查询条件的注意今天是需要过滤查询保单号,使用了 List 作为过滤条

Hibernate 使用 HQL 查询 使用List 作为查询条件的注意

今天是需要过滤查询保单号,使用了 List 作为过滤条件,如下:

HQL:? where id.publicPolicyId in(?)

java:? query.setParameter(0, (ArrayList类型)tmpList);

但是总报错误,

Can not bind to Type java.util.ArrayList

问同事,原来更改条件设置方法:

query.setParameterList("plist", tmpList);

查询成功。

代码如下:

String hql = "select publicPolicyId from TMuster where musterDate >= ? and publicPolicyId between ? and ? ";Query query = session.createQuery(hql);query.setParameter(0, DateUtil.toDate("2010-01-01"));query.setParameter(1, policyIdStart);query.setParameter(2, policyIdEnd);List tmpList = query.list();if(tmpList == null){return null;}// 过滤查询 TPolicyInsurantTemporary 非空条件hql = "select id.publicPolicyId from TPolicyInsurantTemporary where id.publicPolicyId in(:plist) and name <> '' and cert <> '' and cerc <> '' ";query = session.createQuery(hql);query.setParameterList("plist", tmpList);tmpList = query.list();if(tmpList == null){return null;}// 过滤查询 PublicPolicyTemporary 非空条件hql = "from TPublicPolicyTemporary where publicPolicyId in(:plist) and applyName <> '' and applyCert <> '' and applyCerc <> '' and billNo <> '' ";query = session.createQuery(hql);query.setParameterList("plist", tmpList);tmpList = query.list();if(tmpList == null){return null;}rstList = this.TPublicPolicyTrVO(tmpList);

?

热点排行