日期:2014-05-20  浏览次数:20659 次

Hibernate 多表关联查询问题
String sql = “select {t1.*} from cm_document t1,(select max(docid) idnum from cm_document group by doctitle) t2 where t1.docid=t2.idnum and t1.status = 1 order by t1.docpubtime desc”

Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
SQLQuery q = (SQLQuery) session.createSQLQuery(sql).addEntity("t1",CmsDocument.class).addJoin("t2", "t1.t2s");
q.setMaxResults(size);
List<?> list =q.list();

addJoin 怎么写???

------解决方案--------------------
addJoin("别名","第一个实体中的属性如: t1.tab2");