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