这是我的SQL查询
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'))
我将此SQL转换为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);
这会出错:
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))]
答案 0 :(得分:4)
如果你仔细看看这里:customer is not mapped
,我认为很清楚。问题是Hibernate无法找到customer
实体。 HQL中的Java类和属性区分大小写,customer
可能是Customer
。
答案 1 :(得分:0)
我有这个问题,hibernate区分大小写。 这个查询是我的查询: 查询查询= session.createQuery("从学生e中选择e,其中e.id =:id");
我改变了学生, 这个查询是正确的: 查询查询= session.createQuery("从学生e中选择e,其中e.id =:id");