Hibernate hql 多表查询

String hql="select c from Col c ,UserRole role where c.id=role.columnId and c.id=? and role.userId=?";

this.getHibernateTemplate().find(hql,new Object[]{colId,userId}).get(0);

上面返回的是一个对象实体,实体的类型是Col

String hql="from Col c ,UserRole role where c.id=role.columnId and c.id=? and role.userId=?";

this.getHibernateTemplate().find(hql,new Object[]{colId,userId}).get(0);

上面返回的是一个数组  数组的第一个元素类型是Col,第二个元素类型是UserRole

所以在多表查询中,如果要取得某个单独的实体直接用"select c" (c表示该类在查询中的别名)

原文地址:https://www.cnblogs.com/toSeeMyDream/p/4079119.html