Example #1
0
  /* 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();
    }
  }
Example #2
0
 /* 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;
 }
Example #3
0
  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;
  }
Example #4
0
 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;
 }