与HQL中的%运算符一样

时间:2017-10-10 12:22:43

标签: java hibernate jpa orm hql

我正在尝试运行下面的代码但是我收到了错误。

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中使用%运算符。请帮助我。 我也尝试过以下行,但它不起作用。

String hql = "FROM MdFeedHandOff a WHERE a.handoff = :handoff  and  a.active  in ('A','I') and to_char(a.handoff) like :csiID" + "%";

1 个答案:

答案 0 :(得分:2)

您应该在查询中添加:csid参数名称,并在您设置的参数中添加%通配符。你似乎也没有在参数图中设置csid。

<强>查询

FROM MdFeedHandOff a WHERE a.handoff = :handoff 
     and  a.active  in ('A','I') and to_char(a.handoff) like :csiID";

<强> PARAMS

Map<String, Object> param = new HashMap<String, Object>();
param.put("handoff", handoff);
param.put("csiID", csiId.toString()+"%");