Hibernate实现对多个表进行关联查询

Hibernate实现对多个表进行关联查询?

String sTest = “from tBookInfo book, BookSelection sel where book.id = sel.bookId”;
Collection result = new ArrayList();
Transaction tx = null;
try {
 Session session = HibernateUtil.currentSession();
 tx = session.beginTransaction();
 Query query = session.createQuery(sql);
 result = query.list();
 tx.commit();
} catch (Exception e) {
 throw e;
} finally {
 HibernateUtil.closeSession();
}
ArrayList sList = (ArrayList) result;
Iterator iterator1 = sList.iterator();
while (iterator1.hasNext()) {
 Object[] o = (Object[]) iterator1.next();
 tBookInfo bookInfo = (tBookInfo) o[0];
 BookSelection bookSelect = (BookSelection) o[1];
 System.out.println(“BookInfo-Title: ” + bookInfo.getTitle());
 System.out.println(“BookSelection-BookSelectionId: ” + bookSelect.getId());
}

版权声明:本文为javaitpx原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/javaitpx/archive/2012/11/12/2766182.html