Esempio n. 1
0
 public void create(City city) {
   try {
     session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     session.save(city);
     session.getTransaction().commit();
     session.close();
   } catch (Exception e) {
     session.getTransaction().rollback();
     e.printStackTrace();
     session.close();
   }
 }
Esempio n. 2
0
 public City read(int id) {
   City city = null;
   try {
     session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     city = session.get(City.class, id);
     session.getTransaction().commit();
     session.close();
   } catch (Exception e) {
     session.getTransaction().rollback();
     e.printStackTrace();
     session.close();
   }
   return city;
 }