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:classes.ProductAction.java

License:Apache License

public String update() throws Exception {
    logger.info("Starting update()"); //f:log
    Session sess = HibernateUtil.getSessionFactory().openSession(); //f:hibernate
    Transaction t = sess.beginTransaction(); //f:hibernate

    sess.update(this.product); //f:hibernate

    t.commit(); //f:hibernate
    sess.close(); //f:hibernate

    this.task = SystemConstants.UD_MODE;
    this.addActionMessage(this.getText("updateSuccessful", new String[] { "product" }));

    logger.info("Finishing update()"); //f:log
    return INPUT;
}

From source file:classes.PurchaseOrderAction.java

License:Apache License

public String update() throws Exception {
    logger.info("Starting update()"); //f:log
    Session sess = HibernateUtil.getSessionFactory().openSession(); //f:hibernate
    Transaction t = sess.beginTransaction(); //f:hibernate

    for (PurchaseOrderItem item : this.purchaseOrder.getPurchaseOrderItems()) {
        item.setPurchaseOrder(this.purchaseOrder);
    }/*from   ww w .j  av a2  s  .c  o m*/

    sess.update(this.purchaseOrder); //f:hibernate

    t.commit(); //f:hibernate
    sess.close(); //f:hibernate

    this.task = SystemConstants.UD_MODE;
    this.addActionMessage(this.getText("updateSuccessful", new String[] { "order" }));

    logger.info("Finishing update()"); //f:log
    return INPUT;
}

From source file:Clientes.editaCliente.java

private boolean modifica() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*  w w  w .j  av  a2  s.c om*/
        session.beginTransaction();
        Object resp = session.createQuery("from Clientes obj where obj.nombre='" + nombre.getText()
                + "' and obj.idClientes!=" + IdClientes.getText()).uniqueResult();
        if (resp == null) {
            Clientes objeto = (Clientes) session.get(Clientes.class, Integer.parseInt(IdClientes.getText()));
            objeto.setNombre(nombre.getText());
            objeto.setDireccion(Direccion.getText());
            objeto.setColonia(Colonia.getText());
            if (Cp.getText().compareTo("") == 0)
                objeto.setCp(null);
            else
                objeto.setCp(Integer.parseInt(Cp.getText()));
            objeto.setRfc(Rfc.getText().trim());
            objeto.setPoblacion(Poblacion.getText().trim());
            objeto.setEstado(Estado.getSelectedItem().toString().trim());
            objeto.setTelefono(Telefono.getText().trim());
            objeto.setEmail(Email.getText().trim());
            objeto.setContacto(contacto.getText().trim());
            objeto.setNextel(nextel.getText().trim());
            objeto.setMunicipio(municipio.getText().trim());
            objeto.setNumeroExterior(numero.getText().trim());
            objeto.setReceptor(t_receptor.getText());
            objeto.setEmailReceptor(t_email_receptor.getText());
            session.update(objeto);
            session.getTransaction().commit();
            cajas(false);
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "No se pueden guardar nombres duplicados!");
            return false;
        }
    } catch (HibernateException he) {
        he.printStackTrace();
        System.out.println(he.hashCode());
        session.getTransaction().rollback();
        return false;
    } finally {
        if (session.isOpen())
            session.close();
    }
}

From source file:cloudoutput.dao.CustomerRegistryDAO.java

License:Open Source License

/** 
 * Updates an existing customer registry.
 *
 * @param   customer        the customer to be updated.
 * @see                     CustomerRegistry
 * @since                   1.0//w w  w. j a  v  a2  s  .c o m
 */
public void updateCustomerRegistry(CustomerRegistry customer) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.update(customer);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.DatacenterRegistryDAO.java

License:Open Source License

/** 
 * Updates an existing datacenter registry.
 *
 * @param   datacenter      the datacenter to be updated.
 * @see                     DatacenterRegistry
 * @since                   1.0/*ww w  .j a v  a 2 s .c o m*/
 */
public void updateDatacenterRegistry(DatacenterRegistry datacenter) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.update(datacenter);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.HostRegistryDAO.java

License:Open Source License

/** 
 * Updates an existing host registry./*ww  w .j  av  a 2  s .  c  o  m*/
 *
 * @param   hr  the host to be updated.
 * @see         HostRegistry
 * @since       1.0
 */
public void updateHostRegistry(HostRegistry hr) {
    Session session = HibernateUtil.getSession();

    try {
        session.beginTransaction();
        session.update(hr);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.NetworkMapEntryDAO.java

License:Open Source License

/** 
 * Updates an existing network entry.//from   ww w  .j a v  a2  s. c o m
 *
 * @param   entry   the network entry to be updated.
 * @see             NetworkMapEntry
 * @since           1.0
 */
public void updateNetworkMapEntry(NetworkMapEntry entry) {
    Session session = HibernateUtil.getSession();

    try {
        session.beginTransaction();
        session.update(entry);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.SanStorageRegistryDAO.java

License:Open Source License

/** 
 * Updates an existing SAN registry./*from  w  w  w.  j  av a2s . co m*/
 *
 * @param   sr  the customer to be updated.
 * @see         SanStorageRegistry
 * @since       1.0
 */
public void updateSanStorageRegistry(SanStorageRegistry sr) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.update(sr);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.SettingDAO.java

License:Open Source License

/** 
 * Updates an existing setting./*from w w w  . j  a v  a 2s.com*/
 *
 * @param   setting     the setting to be updated.
 * @see                 Setting
 * @since               1.0
 */
public void updateSetting(Setting setting) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.update(setting);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}

From source file:cloudoutput.dao.VirtualMachineRegistryDAO.java

License:Open Source License

/** 
 * Updates an existing virtual machine registry.
 *
 * @param   vr  the customer to be updated.
 * @see         VirtualMachineRegistry/*from  w w  w  .jav  a 2  s .  c o  m*/
 * @since       1.0
 */
public void updateVirtualMachineRegistry(VirtualMachineRegistry vr) {
    Session session = HibernateUtil.getSession();
    try {
        session.beginTransaction();
        session.update(vr);
        session.getTransaction().commit();
    } catch (HibernateException ex) {
        session.getTransaction().rollback();
        Logger.getLogger(Database.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        HibernateUtil.closeSession(session);
    }
}