我的代码
@SuppressWarnings("unchecked")
public List<RemboursementElement> validerRemboursement(String numDossier) {
//List<RemboursementElement> l= getHibernateTemplate().find("from entite.RemboursementElement r where r.NUMERO_DOSSIER_REM='"+numDossier+"'" );
//return l;
List<RemboursementElement> results = Lists.newArrayList();
Session session=null;
try { StringBuilder hql = new StringBuilder();
hql.append("select ");
hql.append(" tableRemboursement.NUMERO_DOSSIER_REM, ");
hql.append("tableRemboursement.MONTANT_REMBOURSE, ");
hql.append("tableRemboursement.ETAT_REMBOURSEMENT, ") ;
hql.append("tableRemboursement.MOTIF_REMBOURSEMENT " );
hql.append("from ");
hql.append(RemboursementElement.class.getCanonicalName());
hql.append(" as tableRemboursement ");
hql.append(" where 1=1 and tableRemboursement.NUMERO_DOSSIER_REM =");
hql.append("'"+numDossier+"'");
hql.append("");
// Query query = getSession().createQuery(hql.toString());
session=this.getSession();
Query query = session.createQuery(hql.toString());
query.setParameter("numDossier", numDossier);
query.executeUpdate();
List<RemboursementElement> l= query.list();
if(l.size()>0 && l.isEmpty()==false && l!=null) {
if(l.iterator().hasNext()==true) {
results.addAll(l);
}
}else {
System.out.println("liste vide !");
}
return results;
} catch (QueryException e) {
throw new HibernateQueryException(e);
}
}
答案 0 :(得分:1)
由您构成的查询是两件事的混合。 您正在以查询格式设置参数,后来又使用了setParameter函数,这会引发异常
在您的代码中,将hq.append("'"+numDossier+"'")
替换为hq.append(":numDossier")