public void add(Asking asking) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tr = session.beginTransaction(); session.save(asking); tr.commit(); session.close(); }
public void update(Asking asking) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tr = session.beginTransaction(); if (null != asking) { session.update(asking); } tr.commit(); session.close(); }
@Override public Asking get(Integer id) { Asking result = new Asking(); Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tr = session.beginTransaction(); result = (Asking) session.get(Asking.class, id); tr.commit(); session.close(); return result; }
@Override public List<Asking> getByReplyUser(User user) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tr = session.beginTransaction(); Criteria cr = session.createCriteria(Asking.class); cr.add(eq("replyUser", user)); List<Asking> result = (List<Asking>) cr.list(); tr.commit(); session.close(); return result; }