@Override public void delete(User user) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query query = session.createQuery("DELETE FROM User where id=" + user.getId()); query.executeUpdate(); session.getTransaction().commit(); } catch (HibernateException e) { log.error("Transaction failed"); session.getTransaction().rollback(); } finally { session.close(); } }
@Override public void update(User user) { // update(product) Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query query = session.createQuery( "update Product set name='" + "lalala" + "' where id=" + user.getId()); query.executeUpdate(); session.getTransaction().commit(); // session.save(product); } catch (HibernateException e) { log.error("Transaction failed"); session.getTransaction().rollback(); } finally { if (session != null) session.close(); } }