Esempio n. 1
0
  public static void main(String[] args) throws HibernateException {
    Session s = HibernateUtil.currentSession();

    Transaction tx = s.beginTransaction();

    // Batiment Copernic = (Batiment) s.load(Batiment.class, new Long(1));
    Iterator itBat = s.iterate("from Batiment");
    while (itBat.hasNext()) {
      Batiment bat = (Batiment) itBat.next();
      System.out.println(bat.getNomBat());
      Iterator etageIt = bat.getEtages().iterator();
      while (etageIt.hasNext()) {
        Etage e = (Etage) etageIt.next();
        System.out.println("\t" + e.getNomEtage());

        Iterator salleIt = e.getSalles().iterator();
        while (salleIt.hasNext()) {
          Salle salle = (Salle) salleIt.next();
          System.out.println(
              "\t\t"
                  + salle.getNomSalle()
                  + "\t"
                  + salle.getTypeSalle()
                  + "\t"
                  + salle.getNbplaces());
        }
      }
    }
    tx.commit();

    HibernateUtil.closeSession();
  }
 private MSystem findSystemFromHibernate() {
   SessionHelper helper = new SessionHelper(mSessions);
   MSystem system = null;
   try {
     Session session = helper.beginTransaction();
     List results = new ArrayList();
     Iterator iterator = session.iterate("from MSystem");
     while (iterator.hasNext()) {
       results.add(iterator.next());
     }
     if (results.size() == 1) {
       system = (MSystem) results.get(0);
     }
   } catch (HibernateException e) {
     LOG.warn("Caught", e);
     helper.rollback(LOG);
   } finally {
     helper.close(LOG);
   }
   return system;
 }