Hibernate多表联合查询结果处理

aa表 对映对象为Aa
id name age
1 11 4
2 22 7
3 33 6
bb表 对映对象为Bb
id aName name
1 11 aa
2 22 bb
3 44 dd

String strSql = "select a.id,a.name,a.age,b.name from Aa a, Bb b where a.name=b.aName";
Query query = session.createQuery(strSql);
List list = query.list();
for(int i=0; i<list.size(); i++) {
Object[] o = (Object[])list.get(i);
System.out.print(o[0] + ",");
System.out.print(o[1] + ",");
System.out.print(o[2] + ",");
System.out.println(o[3]);
}

输出结果为:
1,11,4,aa
2,22,7,bb

你可能感兴趣的:(Hibernate)