簡體   English   中英

找不到命名參數

[英]Could not locate named parameter

我無法理解為什么休眠狀態無法在下面的查詢中找到參數“ setor”。

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();

因為選擇中存在語法錯誤

這個

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

變成

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

您需要在:setororder之前添加一個空白字符。

您必須通過以下方法在扇區和訂單之間留出空間:

像那樣 :

 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM