2

这是我的 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))]

4

2 回答 2

4

如果你仔细看看这里:customer is not mapped,我想它会很清楚。问题是 Hibernate 找不到customer实体。Java 类和属性在 HQL 中区分大小写,可能customerCustomer.

于 2013-06-07T18:13:53.973 回答
0

我有这个问题,休眠是区分大小写的。这个查询是我的查询: Query query = session.createQuery(" select e from student e where e.id=:id");

我将学生更改为学生,此查询是正确的: Query query = session.createQuery(" select e from Student e where e.id=:id");

于 2017-09-03T18:09:11.407 回答