2017-10-10 12 views
1

J'essaye d'exécuter le code ci-dessous mais j'obtiens une erreur.Comme% opérateur dans 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); 
    } 

Je veux utiliser comme opérateur% dans hql. Merci de m'aider. J'ai essayé la ligne ci-dessous, mais ça ne marche pas.

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

ce qui est à l'intérieur searchForList? comment créer une requête et définir les paramètres? –

+0

@SuppressWarnings ("non contrôlée") \t Liste publique searchForList (dernière phrase String, carte finale Paramètres) { \t \t retour (liste) getHibernateTemplate(). Execute (nouvelle HibernateCallback() { \t \t \t public Object doInHibernate (session de session) jette HibernateException { \t \t \t \t query = session.createQuery (phrase); \t \t \t \t query.setProperties (paramètres); \t \t \t \t return query.list(); \t \t \t} \t \t}); \t} –

Répondre

2

Vous devez simplement mettre le nom du paramètre :csid dans la requête et ajoutez le caractère générique% dans le paramètre défini. Aussi, vous ne semblez pas mettre le csid dans la carte params.

Recherche:

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