Categories
hibernate java jpa mysql sql

“org.hibernate.QueryException: Unable to resolve path…” error with parametrized queries on JPA

I’m having a poblem on the first argument of the following method with the parametrized SQL query:

lista = miDao.find("SELECT c FROM Idioma WHERE c.palabra =:param", o1 , entityManager);

where:

String o1= "playa";
List<Object> lista;

The table “Idioma” has 3 columns “palabra”, “idioma” and “wordId”. The method is expected to look for the word “playa” within the column “palabra” and calls to the following Dao method:

@SuppressWarnings("unchecked")
public <T> List<T> find(String queryString, Object param, EntityManager em) {
Query query = em.createQuery(queryString);
query.setParameter( "param" , param);
return query.getResultList();
}

When I run the program I’m “rollbacked” with:

Unable to resolve path [c.palabra], unexpected token [c] [SELECT c FROM com.aprendeidiomas.entity.Idioma WHERE c.palabra =:param]

I’m sure I have a problem with my parametrized sql query. Even though I have red a lot of documents, I cannot solve my error. Could you pleas tell me what is wrong with my parametrized query?

Thank you very much in advance.