List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
From source file:autoancillarieslimited.hiberate.dao.WareHousesDAO.java
public List<WareHouses> getWareHouses() { List<WareHouses> set = null; Session session = null; Transaction beginTransaction = null; try {/* w w w . ja v a 2s . c o m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); set = session.createQuery("from WareHouses").list(); session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.WareHousesDAO.java
public List<WareHouses> getWareHouses(WareHouses filter) { List<WareHouses> set = null; Session session = null; Transaction beginTransaction = null; try {/*from w ww .j ava 2 s. co m*/ session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (filter.getRegion_ID() != 0) { set = session.createQuery("from WareHouses where Name like '%" + filter.getName() + "%' AND Region_ID ='" + filter.getRegion_ID() + "' ").list(); } else { set = session.createQuery("from WareHouses where Name like '%" + filter.getName() + "%'").list(); } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return set; }
From source file:autoancillarieslimited.hiberate.dao.WareHousesDAO.java
public Region getRegionByID(int id) { Region item = null;/*from w w w.ja va 2 s.c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); item = (Region) session.get(Region.class, id); session.flush(); session.clear(); beginTransaction.commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } return item; }
From source file:automatedbillingsoftware_DA.ChallanDA.java
public void deleteChallanGen(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.openSession(); ChallanGenerated cg = fetchChallanGenById(id); System.out.println("id=>" + id + "cg=>" + cg); if (cg != null) { Transaction beginTransaction = session.beginTransaction(); cg.setStatus(0);/*from w w w .j av a2s .c om*/ session.merge(cg); session.flush(); System.out.println("cg=>" + cg.getStatus()); // challan.setStatus(1); // session.persist(challan); beginTransaction.commit(); } // return challan; }
From source file:automatedbillingsoftware_DA.ChallanDA.java
public ChallanGenerated updateChallanGen(ChallanGenerated challan) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.update(challan);/*from w w w .j a v a 2 s . com*/ session.flush(); beginTransaction.commit(); return challan; }
From source file:automatedbillingsoftware_DA.User_DA.java
public void deleteUser(int id) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); Users userId = fetchUserById(id);/*w ww. j av a2 s .c om*/ userId.setStatus(0); session.update(userId); session.flush(); // session.saveOrUpdate(users); beginTransaction.commit(); // return users; }
From source file:automatedbillingsoftware_DA.User_DA.java
public void updateUser(Users user) { SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory(); Session session = sessionFactory.getCurrentSession(); Transaction beginTransaction = session.beginTransaction(); session.update(user);//from ww w . j a va2s .com session.flush(); // session.saveOrUpdate(users); beginTransaction.commit(); // return users; }
From source file:banco.UsuarioDAO.java
public void addUsuario(Usuario usuario) { Transaction trns = null;/* ww w . j a va 2 s . c o m*/ SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); try { trns = session.beginTransaction(); session.save(usuario); session.getTransaction().commit(); } catch (RuntimeException e) { if (trns != null) { trns.rollback(); } e.printStackTrace(); } finally { session.flush(); session.close(); } }
From source file:banco.UsuarioDAO.java
public boolean checkRegister(Usuario usuario) { List<Usuario> listUsuario = new ArrayList<Usuario>(); Transaction trns = null;/*w ww .ja va2 s .c om*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); listUsuario = session.createQuery("from Usuario").list(); for (Usuario key : listUsuario) { if (key.getSenha().equals(usuario.getSenha()) || key.getLogin().equals(usuario.getLogin())) { return false; } } } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return true; }
From source file:banco.UsuarioDAO.java
public long getIdByUser(Usuario usuario) { List<Usuario> listUsuario = new ArrayList<Usuario>(); Transaction trns = null;// ww w .j a v a 2 s . com Session session = HibernateUtil.getSessionFactory().openSession(); try { trns = session.beginTransaction(); listUsuario = session.createQuery("from Usuario").list(); for (Usuario key : listUsuario) { if (key.getSenha().equals(usuario.getSenha()) && key.getLogin().equals(usuario.getLogin())) { return key.getId(); } } } catch (RuntimeException e) { e.printStackTrace(); } finally { session.flush(); session.close(); } return -1; }