hibernate里怎么使用join来联接表
select tu.* from t_user tu join t_group_users tgu on tu.id=tgu.userid where tgu.groupid=3
我想把上面语句传成HQL语法,应该要怎么写?(两表已经在配置文件里建立了关系的)
我写成下面:
select t_user.id from User as t_user join GroupUsers as t_group_users on t_user.id=t_group_users.user.id where t_group_users.group.id=3
报错on 关键有错,不知道具体join在HQL里面到底要怎么写。。。。求救
------解决方案--------------------俺也不会 正在学习中
------解决方案--------------------public List getList() {
Session session = this.getSession();
List list = session.createSQLQuery( "select {u.*}, {b.*} fromUser u inner join UnionUser b where u.id = b.UserId ").addEntity( "u ", User.class).addEntity( "b ", UnionUser.class).list();
return list;
}