QuerySyntaxException: unexpected token:. near

0

This is the error I believe is easy for those who handle Java but as I am learning I still 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's my CidadeDAO.java

@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 then Thank you in advance.

UPDATE: Error after inserted WHERE:

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

Status

    
asked by anonymous 03.03.2015 / 17:41

2 answers

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.Cidade c.estado =: est]

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

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

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

    
03.03.2015 / 17:47
2

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

select c from Cidade where c.estado = :est
    
03.03.2015 / 17:43