HQL 子选择错误

Error on HQL subselect

我 运行 这个查询在 WHERE 子句中有一个子选择

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

我看到你的计数是 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