示例#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;
 }