예제 #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();
   }
 }
예제 #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;
 }