Exemplo n.º 1
0
 @Override
 public void delete(Entity obj) {
   try {
     this.session = HibernateUtil.openSession();
     this.session.beginTransaction();
     this.session.delete(obj);
     this.session.getTransaction().commit();
   } catch (Exception e) {
     this.session.getTransaction().rollback();
   } finally {
     session.close();
   }
 }
Exemplo n.º 2
0
 @Override
 @SuppressWarnings("unchecked")
 public List<Entity> getAll() {
   List<Entity> list = null;
   try {
     this.session = HibernateUtil.openSession();
     this.session.beginTransaction();
     list = this.session.createCriteria(entityClass).list();
     this.session.getTransaction().commit();
   } catch (HibernateException e) {
     this.session.getTransaction().rollback();
   } finally {
     session.close();
   }
   return list;
 }
Exemplo n.º 3
0
 @Override
 public Long create(Entity obj) {
   Long id = null;
   try {
     this.session = HibernateUtil.openSession();
     this.session.beginTransaction();
     id = (Long) this.session.save(obj);
     this.session.getTransaction().commit();
   } catch (Exception e) {
     Logger.getLogger(EntityDao.class.getName()).log(Level.SEVERE, null, e);
     this.session.getTransaction().rollback();
   } finally {
     session.close();
   }
   return id;
 }
Exemplo n.º 4
0
  @Override
  @SuppressWarnings("unchecked")
  public Entity getById(Long entityId) {
    Entity entity = null;
    try {
      this.session = HibernateUtil.openSession();
      this.session.beginTransaction();
      List<Entity> list = null;
      list = this.session.createCriteria(entityClass).add(Restrictions.eq("id", entityId)).list();
      if (list.size() > 0) {
        entity = list.get(0);
      }
      this.session.getTransaction().commit();
    } catch (HibernateException e) {
      this.session.getTransaction().rollback();
    } finally {

    }
    return entity;
  }