Search code examples
hibernatehql

Error org.hibernate.hql.internal.ast.QuerySyntaxException


This is my SQL query

select * from customer where cust_acnt_nbr IN (select cust_acnt_nbr from Asset where dstrct_id IN (select dstrct_id from dstrct where dstrct_nm = 'ATLANTA'))

I converted this SQL to HQL

    final Query query = getCurrentSession().createQuery(
            "from customer where cust_acnt_nbr in (select cust_acnt_nbr from Asset where dstrct_id in (select dstrct_id from dstrct where dstrct_nm = :name))");
    query.setParameter("name", districtName);

This give an error :

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.hql.internal.ast.QuerySyntaxException: customer is not mapped [from customer where cust_acnt_nbr in (select cust_acnt_nbr from com.ironmountain.model.Asset where dstrct_id in (select dstrct_id from dstrct where dstrct_nm = :name))]


Solution

  • If you take a closer look here: customer is not mapped, i think it will be clear. The problem is that Hibernate can't find the customer entity. Java classes and properties are case sensitive in HQL, maybe customer is meant to be Customer.