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());

你可能感兴趣的:(Hibernate,exception,object,session,iterator,query)