【发布时间】:2018-03-21 20:34:36
【问题描述】:
我正在尝试运行下面的代码,但出现错误。
public MdFeedHandOff getFeedByHandOff(Integer handoff, Integer csiID){
logger.error("*************getFeedByHandOff(): handoff value is "+handoff);
String hql = "FROM MdFeedHandOff a WHERE a.handoff = :handoff and a.active in ('A','I') and to_char(a.handoff) like :csiID%";
Map<String, Object> param = new HashMap<String, Object>();
param.put("handoff", handoff);
List<MdFeedHandOff> batchJobList = searchForList(hql, param);
return batchJobList.isEmpty()?null:batchJobList.get(0);
}
我想在 hql 中使用 like % 运算符。请帮助我。 我也尝试过以下行,但它不起作用。
String hql = "FROM MdFeedHandOff a WHERE a.handoff = :handoff and a.active in ('A','I') and to_char(a.handoff) like :csiID" + "%";
【问题讨论】:
-
searchForList 里面有什么?如何创建查询并设置参数?
-
@SuppressWarnings("unchecked") public List searchForList(final String sentence, final Map
parameters) { return (List) getHibernateTemplate().execute(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException { Query query = session.createQuery(sentence); query.setProperties(parameters); return query.list(); } }); }
标签: java hibernate jpa orm hql