怎么显示 姓名,用户名,部门,级别
看看类似下面的是什么效果
sess.createSQLQuery("SELECT c.ID, NAME, BIRTHDATE, DOG_ID, D_ID, D_NAME FROM CATS c, DOGS d WHERE c.DOG_ID = d.D_ID")
.addEntity("cat", Cat.class)
.addJoin("cat.dog");
16.1.3. Handling associations and collections
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querysql
+1用left join 关联查询。 createSQLQuery (sql) 就可以的
主要是用连接操作,左右外链,内联。例如:学员—班级
Select c.name , s.name from Student s inner join s.classes c
外联(左、右外联)
班级—学员
Select c.name, s.name from Classes c left join c.students s
Select c.name, s.name from Classes c right join c.students s
然后用:createQuery(sql语句)就行了
+1