下面列举一个完整的例子来说明Hibernate对多个表进行关联查询(其中粗体是我们要特别注意的地方相应表tBookInfo和BookSelection的结构和其对应的hbmxmlclass文件就不一一列举了有需要详细了解的朋友请联系我)
String sTest = from tBookInfo book BookSelection sel where bookid = selbookId;
Collection result = new ArrayList();
Transaction tx = null;
try {
Session session = HibernateUtilcurrentSession();
tx = sessionbeginTransaction();
Query query = sessioncreateQuery(sql);
result = querylist();
mit();
} catch (Exception e) {
throw e;
} finally {
HibernateUtilcloseSession();
}
ArrayList sList = (ArrayList) result;
Iterator iterator = erator();
while (iteratorhasNext()) {
Object[] o = (Object[]) iteratornext();
tBookInfo bookInfo = (tBookInfo) o[];
BookSelection bookSelect = (BookSelection) o[];
Systemoutprintln(BookInfoTitle: + bookInfogetTitle());
Systemoutprintln(BookSelectionBookSelectionId: + bookSelectgetId());
}