熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

Hibernate對多個表進行關聯查詢實例

2022-06-13   來源: Java開源技術 

  下面列舉一個完整的例子來說明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());

  }


From:http://tw.wingwit.com/Article/program/Java/ky/201311/27865.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.