Hibernate hql 多表查询

时间:2014-11-06 16:46:05   收藏:0   阅读:275
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表示该类在查询中的别名)

原文:http://www.cnblogs.com/toSeeMyDream/p/4079119.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!