Error with Unexpected JPQL token

Asked

Viewed 907 times

0

I made a select JPQL but I’m having this error:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: where near line 1, column 151 [select pes, pEnd from digifred.model.global.Pessoas pes, digifred.model.global.PessoasEnderecos pEnd where pes.entidade.idEntidade = :parametroId and where pEnd.entidade.idEntidade=:parametroId]
    at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:288) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]

My method is like this:

@Query( value="select pes, pEnd from Pessoas pes, PessoasEnderecos pEnd where pes.entidade.idEntidade = :parametroId and where pEnd.entidade.idEntidade=:parametroId" )
    public  Collection<Pessoas>  encontrar(@Param("parametroId") Long usuarioEntidade);
  • you are using spring ?

  • Yes, I’m using Spring boot

  • https://spring.io/blog/2014/07/15/spel-support-in-spring-data-jpa-query-definitions Only the shape of your parameter is wrong : #{#parametroId.identity} : ? #{[parametroId]} For being long

  • If you can put as an answer there with my code so I can see better..

  • You are using HQL syntax, only use JPQL inside your code. Ta run in the trampo, but wait I’ll tidy up

1 answer

2


This is your query, with a few more line breaks:

select pes, pEnd
from Pessoas pes, PessoasEnderecos pEnd
where pes.entidade.idEntidade = :parametroId
and where pEnd.entidade.idEntidade=:parametroId

Watch this and where on that last line. That’s wrong, it was supposed to be just and. That is, remove the second word where:

select pes, pEnd
from Pessoas pes, PessoasEnderecos pEnd
where pes.entidade.idEntidade = :parametroId
and pEnd.entidade.idEntidade=:parametroId

Browser other questions tagged

You are not signed in. Login or sign up in order to post.