Querysyntaxexception: Unexpected token: . near

Asked

Viewed 4,617 times

0

This is the mistake I believe is easy for those who know Java but as I am learning I have not identified the problem.

GRAVE: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: . near line 1, column 49 [select c from com.htcursos.model.entity.Cidade c.estado=:est]

Here is my City.

@SuppressWarnings("unchecked")
public List<Cidade> buscarCidades(Estado estado) {
    Query consulta = em.createQuery("select c from Cidade c.estado=:est");//JPQL
    consulta.setParameter("est", estado);
    return consulta.getResultList();
}

If this is not enough to solve the problem, ask me for more information that I add to the post. All the help is much appreciated so thank you from now on.

UPDATE: Error after WHERE inserted:

GRAVE: java.lang.IllegalArgumentException: org.hibernate.QueryException: Unable to resolve path [c.estado], unexpected token [c] [select c from com.htcursos.model.entity.Cidade where c.estado=:est]

Tables

City

inserir a descrição da imagem aqui

State

inserir a descrição da imagem aqui

2 answers

2

Your query is wrong, the word is missing where in it.

select c from Cidade where c.estado = :est

2


According to the error returned:

java.lang.Illegalargumentexception: org.hibernate.hql.internal.Ast.Querysyntaxexception: Unexpected token: . near line 1, column 49 [select c from com.htcursos.model.entity.City c.state=:est]

The problem is in the syntax of query (QuerySyntaxException), I believe that according to your need you could use the query below (with the WHERE):

SELECT c.nome FROM Cidade c WHERE c.estado =:est

Placed c.nome because I believe you need the name of the city.

  • I put Where but another error was shown, & #Xa; org.hibernate.Queryexception: Unable to resolve path [c.status]

  • could add the other error to the question?

  • @Zuqui could add details about the bank you are trying to query?

  • The one on the left is the city table and the right state

  • What is the purpose of this method you are implementing (which data you want to search for in the bank)?

  • I want to search the city that has the status id equal to the status table id.

  • @Zuqui updated the answer

  • @Zuqui, I changed the query. Try this if it doesn’t work answer me here.

  • 1

    Hi williamhk2 worked yes thank you very much

Show 4 more comments

Browser other questions tagged

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