List of usage examples for org.hibernate Session clear
void clear();
From source file:autoancillarieslimited.hiberate.dao.PurchaseOrderDAO.java
public Long getCountOrder(String dateFrom, String dateTo, String status, String warehouse) { Long set = null;/*from w ww .ja va 2s. c o m*/ Session session = null; Transaction beginTransaction = null; try { session = HibernateUtil.getSessionFactory().openSession(); beginTransaction = session.beginTransaction(); if (dateFrom != null && dateTo != null && !dateFrom.equals("") && !dateTo.equals("") && status != null && warehouse != null && !warehouse.equals("all")) { set = (Long) session.createQuery("select count(*) from PurchaseOrder where ID_Warehouse like '" + warehouse + "' AND Date_Order >='" + dateFrom + "' AND Date_Order <='" + dateTo + "' AND Status like '" + status + "'").uniqueResult(); } else { if (dateFrom != null && dateTo != null && !dateFrom.equals("") && !dateTo.equals("") && status != null) { if (Integer.parseInt(status) != -1) { set = (Long) session .createQuery("select count(*) from PurchaseOrder where Date_Order >='" + dateFrom + "' AND Date_Order <='" + dateTo + "' AND Status like '" + status + "'") .uniqueResult(); } else { set = (Long) session.createQuery("select count(*) from PurchaseOrder where Date_Order >='" + dateFrom + "' AND Date_Order <='" + dateTo + "'").uniqueResult(); } } else { set = (Long) session.createQuery("select count(*) from PurchaseOrder").uniqueResult(); } } session.flush(); session.clear(); session.getTransaction().commit(); } catch (HibernateException ex) { ex.printStackTrace(); if (beginTransaction != null) { beginTransaction.rollback(); } } finally { if (session != null) { session.close(); } } long countPage = set / pageSize; if (set % pageSize > 0) { countPage++; } return countPage; }
From source file:autoancillarieslimited.hiberate.dao.WareHousesDAO.java
public List<WareHouses> getWareHouses() { List<WareHouses> set = null; Session session = null; Transaction beginTransaction = null; try {//from w w w. j a v a 2 s .c om 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 {/*w w w. ja v a 2 s. c om*/ 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 . jav a 2 s . c om*/ 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:br.com.gaiatosfc.DAO.JogadoresDAOImp.java
@Override public void salvar(Jogadores jogador) throws DAOException { Session session = null; try {// w ww . j a v a2 s .c om session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); session.save(jogador); t.commit(); session.flush(); session.clear(); } catch (Exception e) { session.getTransaction().rollback(); throw new DAOException(e); } finally { if (session != null) { session.close(); } } }
From source file:br.com.gaiatosfc.DAO.JogadoresDAOImp.java
@Override public void deletar(Jogadores jogador) throws DAOException { Session session = null; try {/*from w ww .j a va2s .c o m*/ session = HibernateUtil.getSessionFactory().openSession(); Transaction t = session.beginTransaction(); session.flush(); session.delete(jogador); t.commit(); session.clear(); } catch (Exception e) { session.getTransaction().rollback(); throw new DAOException(e); } finally { if (session != null) { session.close(); } } }
From source file:br.com.pfood.produces.SessionProdutor.java
public void fechaSession(@Disposes Session session) { session.clear(); session.close();/*from w w w . j a va 2s .c o m*/ session = null; logger.debug("Sessao hibernate fechada"); }
From source file:br.com.pucminas.debt.dao.impl.ValorMetricaDAOImpl.java
@Override public void salvar(List<ValorMetrica> valoresMetrica) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction t = null;/*from w ww . j a va2 s. c o m*/ try { session.beginTransaction(); for (ValorMetrica val : valoresMetrica) { if (val.getValor() != null) { val.setId(0); session.save(val); session.flush(); session.clear(); } } session.getTransaction().commit(); } catch (HibernateException e) { if (t != null) { t.rollback(); } } finally { session.close(); } }
From source file:br.msf.commons.persistence.dao.AbstractEntityDaoBean.java
License:Open Source License
@Override public void flush() { final Session session = getCurrentSession(); session.flush(); session.clear(); }
From source file:br.ufg.calendario.dao.CalendarioDao.java
@Transactional public boolean adicionar(Calendario calendario) { Session session = sessionFactory.getCurrentSession(); try {//from www . j a v a 2 s . c o m session.save(calendario); if (calendario.isAtivo() == true) { disableOthers(session, calendario); } return true; } catch (HibernateException e) { System.out.println(e.getMessage()); session.clear(); return false; } }