我是 HQL 的新手,这件事让我很困惑。所以,这是我拥有的功能:
public List<Map<String, Object>> getMyQuery(List<Country> country){
String hql = "SELECT DISTINCT new map(a as accounts) ";
hql += "FROM Account a WHERE a.location_id in "
+ "( "
+ "SELECT location_id FROM Location l WHERE l.address_id in "
+ "("
+ "SELECT id FROM Address adr WHERE adr.country_id in (:country)))";
}
Query query = getSession().createQuery(hql);
if(country != null){
query.setParameterList("country", country);
}
return query.list();
}
在我的日志文件中,我看到由于以下原因无法解析查询:
Caused by: org.hibernate.QueryException: could not resolve property: country_id of: com.mypackage.myobjects.Address [SELECT id FROM com.mypackage.myobjects.Address adr WHERE adr.country_id in (:country)]
当我在 using SQL db 上运行类似的查询时,一切都很好,但是这个中断了。我想知道为什么文件夹中突然输出包?似乎查询是在对象上执行的,而不是在数据库上。我究竟做错了什么?
先感谢您