Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

In this page you can find the example usage for org.hibernate Session update.

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:com.almacen.dao.empleadoDaoImp.java

@Override
public Empleado actualizaEmpleado(Empleado empleado) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {/*from w  w  w.j a  va2s  . c  o m*/

        session.update(empleado);
        transaction.commit();
        session.close();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        transaction.rollback();
    }
    return empleado;
}

From source file:com.almacen.dao.facturaDaoImp.java

@Override
public Factura actualizaFactura(Factura factura) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();

    try {//  w  ww .  ja v  a 2 s .c  o  m

        session.update(factura);
        transaction.commit();
        session.close();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        transaction.rollback();
    }
    return factura;
}

From source file:com.almacen.dao.proveedorDaoImp.java

@Override
public Proveedor guardaProveedor(Proveedor prov) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {/*from  www  . j a v  a  2  s. com*/

        if (prov.getIdProveedor() == null || prov.getIdProveedor() == 0) {
            session.save(prov);
            transaction.commit();
            session.close();

        } else {
            session.update(prov);
            transaction.commit();
            session.close();
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        transaction.rollback();
    }
    return prov;
}

From source file:com.almacen.dao.salidaDaoImp.java

@Override
public boolean actualizaSalida(Salida salida) {
    boolean esCorrecto = true;
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transaction = session.beginTransaction();
    try {//w  w w.  j  a  v  a  2 s  .c  om

        session.update(salida);
        transaction.commit();
        session.close();

    } catch (Exception e) {
        System.out.println(e.getMessage());
        transaction.rollback();
        esCorrecto = false;
    }
    return esCorrecto;
}

From source file:com.altcolorlab.simplehibernategui.ManageEmployee.java

public void updateEmployee(Integer EmployeeID, int salary) {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session session = sf.openSession();
    Transaction tx = null;//  w  ww .ja va  2  s  .  com
    try {
        tx = session.beginTransaction();
        Employee employee = (Employee) session.get(Employee.class, EmployeeID);
        employee.setSalary(salary);
        session.update(employee);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
}

From source file:com.apt.facade.AdminFacade.java

public void updateAdmin(int adminID, Byte status) {
    Session session = null;
    Transaction trans = null;//from   ww w  .j  a v a 2  s  .  c om
    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Admin admin = (Admin) session.get(Admin.class, adminID);
        admin.setStatus(status);
        session.update(admin);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
}

From source file:com.apt.facade.AdminFacade.java

public void updateAdmin(Admin admin) {
    Session session = null;
    Transaction trans = null;/* w w w  .  ja  v  a  2s.c o m*/

    try {

        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        session.update(admin);
        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
}

From source file:com.apt.facade.AssignmentFacade.java

public boolean updateAssignment(int assignmentID, Byte status) {
    Session session = null;
    Transaction trans = null;//  ww w . j av  a  2s  .  co  m
    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Assignment assignment = (Assignment) session.get(Assignment.class, assignmentID);
        assignment.setStatus(status);
        session.update(assignment);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
        return false;
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
    return true;
}

From source file:com.apt.facade.AssignmentFacade.java

public void updateAssignment(Assignment assignment) {
    Session session = null;
    Transaction trans = null;/*from  w w  w  . jav  a 2 s.co  m*/
    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        session.update(assignment);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
}

From source file:com.apt.facade.BatchFacade.java

public void updateBatch(Batch batch) {
    Session session = null;
    Transaction trans = null;//from  w  w w . j  a v  a 2  s  .  c o m

    try {
        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        session.update(batch);

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
}