2017-10-10 3 views
1

以下のコードを実行しようとしていますが、エラーが発生しています。HQLの%operatorと似ています

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" + "%"; 
+0

いただきましsearchForList内部?どのようにクエリを作成し、パラメータを設定するには? \t公共一覧searchForList(最終文字列の文章、最後の地図<文字列、オブジェクト>パラメータ){ \t \tリターン(一覧)getHibernateTemplate()。実行(新HibernateCallback(){ \t \t \t –

+0

@SuppressWarnings( "未チェック")パブリックオブジェクトdoInHibernate(セッションセッション)HibernateExceptionで{ \t \t \t \tクエリのクエリ= session.createQuery(文章)をスロー; \t \t \t \t query.setProperties(パラメータ); \t \t \t \t return query.list(); \t \t \t} \t \t}); \t} –

答えて

2

あなただけのクエリで:csidパラメータ名を入れて、あなたが設定したパラメータの%ワイルドカードを追加する必要があります。また、paramsマップに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()+"%"); 
関連する問題