CodeMed
CodeMed

Reputation: 9181

unexpected token in select statement

In a spring mvc app using hibernate and jpa, I am getting an unexpected token error when running the following query:

@SuppressWarnings("unchecked")
public Collection<Description> findDescriptionsByConceptId(BigInteger id) {
    Query query = this.em.createQuery("SELECT desc FROM Description desc WHERE desc.concept.conceptPk.id =:cid");
    query.setParameter("cid", id);
    return query.getResultList();
}

Here is the error message:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException:  
unexpected token: desc near line 1, column 8  
[SELECT desc FROM myapp.Description desc WHERE desc.concept.conceptPk.id =:cid]

How can I resolve this error message? I would post more code, but I have no idea what is causing this error.

Upvotes: 0

Views: 7794

Answers (2)

Alexandre Santos
Alexandre Santos

Reputation: 8338

This worked for me:

@SuppressWarnings("unchecked")
public Collection<Description> findDescriptionsByConceptId(BigInteger id) {
    Query query = this.em.createQuery("SELECT tblDesc FROM Description tblDesc WHERE tblDesc.concept.conceptPk.id =:cid");
    query.setParameter("cid", id);
    return query.getResultList();
}

Upvotes: 1

jordan
jordan

Reputation: 1017

"desc" is commonly a reserved word, used in "order by" to represent descending value. Can you rename the column or surround it by quotes?

Upvotes: 2

Related Questions