/* Method to DELETE State */ public void deleteState(Integer key) { Transaction tx = null; try { session = HibernateUtil.currentSession(); tx = session.beginTransaction(); State obj = (State) session.get(State.class, key); session.delete(obj); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } }
/* Method to INSERT State */ public Long addState(State obj) { Transaction tx = null; Long key = null; try { session = HibernateUtil.currentSession(); tx = session.beginTransaction(); key = (Long) session.save(obj); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); e.printStackTrace(); } return key; }
public State findById(Integer id) { State State = null; Transaction tx = null; try { session = HibernateUtil.currentSession(); tx = session.beginTransaction(); State = (State) session.get(State.class, id); tx.commit(); } catch (Exception e) { if (tx != null && session.isOpen()) tx.rollback(); e.printStackTrace(); } return State; }
public List listStates() { LOGGER.setLevel(Level.INFO); List<State> list = new ArrayList<State>(); Transaction tx = null; try { session = HibernateUtil.currentSession(); tx = session.beginTransaction(); list = session.createQuery("FROM State").list(); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } e.printStackTrace(); } return list; }