我正在尝试使用条件加入多个表以加入但遇到一些问题,请帮助我:我有一个 sql 查询,例如:
SELECT a.type, a.time, c.code AS exchangeCode
FROM CutOffTime AS a INNER JOIN
Country AS b ON a.country_fk = b.id INNER JOIN
Exchange AS c ON c.country_fk = b.id
这三个表:CutOffTime(有国家)、Country、Exchange(有国家)是3个实体类。
我如何使用休眠标准加入这样的,我下面的代码仍然不完整:
List<Map<String, Object>> aa= ( List<Map<String, Object>>) getHibernateTemplate().executeFind(new HibernateCallback() {
@Override
public Object doInHibernate(final Session session) throws HibernateException, SQLException {
final Criteria c = session.createCriteria(CutOffTime.class,"cutofftime");
c.createAlias("cutofftime.country", "country");
final Criteria c2= session.createCriteria(Exchange.class,"exchange");
c2.createAlias("exchange.country", "country");
// c.add(Restrictions.eqProperty("cutofftime.country.id","exchange.country.id"));
return c.list();
}
});