/* (non-Javadoc) * @see br.edu.infnet.authsample.service.util.BaseService#findAll() */ @SuppressWarnings("unchecked") @Override public List<T> findAll() { List<T> list = new ArrayList<T>(); try { session = HibernateUtils.getSession(); list = session.createCriteria(this.clazz).list(); } catch (Exception e) { LOGGER.error("Error retrieving all entities.", e); } finally { session.close(); } return list; }
/* (non-Javadoc) * @see br.edu.infnet.authsample.service.util.BaseService#persist(java.lang.Object) */ @Override public void persist(T entity) { try { session = HibernateUtils.getSession(); session.beginTransaction(); session.saveOrUpdate(entity); session.getTransaction().commit(); } catch (Exception e) { session.getTransaction().rollback(); LOGGER.error("Error persisting entity.", e); } finally { session.close(); } }
/* (non-Javadoc) * @see br.edu.infnet.authsample.service.util.BaseService#find(java.lang.Integer) */ @SuppressWarnings("unchecked") @Override public T find(Integer id) { T entity = null; try { session = HibernateUtils.getSession(); entity = (T) session.get(this.clazz, id); } catch (Exception e) { LOGGER.error("Error retrieving entity by identifier. id: " + id, e); } finally { session.close(); } return entity; }