查询集合
String sql = "select id, address,userid from t_address where userid in(select id from t_user where id in (select id from t_card where cardnum=112))";
SQLQuery query = session.createSQLQuery(sql).addEntity(Address.class);
List list = session.createSQLQuery(sql).list();
for(Object a : list){
Object[] address = (Object[]) a;
System.out.println(address[0]+" "+address[1]+" "+address[2]);
}
查询一个对象
String sql = "select id,username,password from t_user where id in (select id from t_card where cardnum=112)";
SQLQuery query = session.createSQLQuery(sql).addEntity(User.class);
User user = (User) query.uniqueResult();
System.out.println(user.getPwd());