nori
nori

Reputation: 115

Could not locate named parameter

I am not able to understand why the hibernate is not finding the parameter "setor" of the query below.

hql.append("select top :limite * from MA3OCORT oco,MA4DETOT ocodA " +
           "    where MA4IDOCO=ma3idoco " +
           "    and ocodA.MA4IDODE in (select max(ocodB.MA4IDODE) from MA4DETOT ocodB where ocodA.MA4IDOCO=ocodB.MA4IDOCO and ocodB.MA4IDSIT=:situacao)" +
           "    and (oco.MA3DSSOL like :solicitante or :solicitante is null)" +
           "    and (ocodA.MA4DTDET between :datai and :dataf or :dataf is null)" +
           "    and ocodA.MA4IDSET = :setor" +
           "order by ocodA.MA4DTDET desc");

return em.createNativeQuery(hql.toString(), OcorrenciaDetalhe.class)
       .setParameter("situacao", situacao)
       .setParameter("solicitante",  "%" + solicitanteFiltro + "%")
       .setParameter("datai", dataRespostaFiltro1)
       .setParameter("dataf", dataRespostaFiltro2)
       .setParameter("setor", usuarioLogado.getSetor().getId())
       .setParameter("limite", limit).getResultList();

Upvotes: 0

Views: 198

Answers (2)

Abder KRIMA
Abder KRIMA

Reputation: 3678

You have to make a space between sector and order by:

like that :

 hql.append("select top :limite * from MA3OCORT oco,MA4DETOT ocodA " +
       "    where MA4IDOCO=ma3idoco " +
       "    and ocodA.MA4IDODE in (select max(ocodB.MA4IDODE) from MA4DETOT ocodB where ocodA.MA4IDOCO=ocodB.MA4IDOCO and ocodB.MA4IDSIT=:situacao)" +
       "    and (oco.MA3DSSOL like :solicitante or :solicitante is null)" +
       "    and (ocodA.MA4DTDET between :datai and :dataf or :dataf is null)" +
       "    and ocodA.MA4IDSET = :setor" +
       "    order by ocodA.MA4DTDET desc");

 return em.createNativeQuery(hql.toString(), OcorrenciaDetalhe.class)
   .setParameter("situacao", situacao)
   .setParameter("solicitante",  "%" + solicitanteFiltro + "%")
   .setParameter("datai", dataRespostaFiltro1)
   .setParameter("dataf", dataRespostaFiltro2)
   .setParameter("setor", usuarioLogado.getSetor().getId())
   .setParameter("limite", limit).getResultList();

Upvotes: 0

SubOptimal
SubOptimal

Reputation: 22973

Because there is a syntax error in the select

this

"   and ocodA.MA4IDSET = :setor" +
"order by ocodA.MA4DTDET desc");

becomes

'   and ocodA.MA4IDSET = :setororder by ocodA.MA4DTDET desc'

You need to add a blank character after :setor or before order.

Upvotes: 2

Related Questions