2017-09-01 111 views
0

我運行這個查詢與子查詢的WHERE子句錯誤的HQL子查詢

select prot.id as id, 
      prot.nrProtocolo as nrProtocolo, 
      prot.nrAno as nrAno, 
      prot.cdSituacaoProtocolo as cdSituacaoProtocolo, 
      prot.palavraChave as palavraChave, 
      prot.dsObs as dsObs, 
      prot.dataCriacao as dataCriacao, 
      partAtual as participanteAtual, 
      assunto.id as assunto_id, 
      assunto.nmAssunto as assunto_nmAssunto, 
      tema.id as assunto_tema_id, 
      tema.nmTema as assunto_tema_nome 
    from Evento evt 
    inner join evt.protocolo prot 
    left outer join prot.assunto assunto 
    left outer join assunto.tema tema 
    inner join prot.participanteAtual partAtual 
    where (
      (prot.participanteSubscritor.id = :participanteId and :participanteId is not null) or 
      (upper(prot.nmSubscritor) like :nmParticipante and :nmParticipante is not null) or 
      (prot.participanteEmissor.id = :participanteId and :participanteId is not null) or 
      (upper(prot.nmEmissor) like :nmParticipante and :nmParticipante is not null) or 
      (
       select count(*) from ParticipanteProtocoloEntity pp where pp.protocolo.id = prot.id and 
       ( 
        (pp.participante.id = :participanteId and :participanteId is not null) or 
        (upper(pp.nmParticipante) like :nmParticipante and :nmParticipante is not null) > 0 
       ) 
      ) 
     ) 
      and trunc(prot.dataCriacao) >= trunc(:periodoInicial) and trunc(prot.dataCriacao) <= trunc(:periodoFinal) 
      and prot.cdSituacaoProtocolo <> 4 
      and prot.cdSituacaoProtocolo <> 8 
      and (prot.snExcluido is null or prot.snExcluido != 'S') 
    order by prot.dataCriacao desc, prot.nrProtocolo asc 

內,但我收到此錯誤:

Error in named query: 
Protocolo.recuperaListaProtocoloPorEncaminhadoParticipanteTrans: 
org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: query 

當我刪除子選擇查詢工作正常。

我不能發現什麼是錯的這一部分:

(
    select count(*) from ParticipanteProtocoloEntity pp where pp.protocolo.id = prot.id and 
       ( 
        (pp.participante.id = :participanteId and :participanteId is not null) or 
        (upper(pp.nmParticipante) like :nmParticipante and :nmParticipante is not null) > 0 
       ) 
) 

回答

0

我看到你得到的ParticipanteProtocoloEntity計數。但它看起來畸形的對我說:

(UPPER(pp.nmParticipante) LIKE :nmParticipante AND :nmParticipante IS NOT NULL) > 0 

看起來像{boolean statement} > 0給我。我猜你想count(*)大於零:

(
SELECT 
    COUNT(*) 
FROM 
    ParticipanteProtocoloEntity pp 
WHERE 
    pp.protocolo.id = prot.id 
AND ((
      pp.participante.id = :participanteId 
     AND :participanteId IS NOT NULL) 
    OR (
      UPPER(pp.nmParticipante) LIKE :nmParticipante 
     AND :nmParticipante IS NOT NULL))) > 0