Example usage for org.hibernate Session merge

List of usage examples for org.hibernate Session merge

Introduction

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

Prototype

Object merge(Object object);

Source Link

Document

Copy the state of the given object onto the persistent object with the same identifier.

Usage

From source file:controller.AluguelPecaController.java

@Override
public void atualizarHerdeiro() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {//from w  w  w . j a va  2 s.com
        s.merge(this.peca);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Dado Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();
}

From source file:controller.CategoriaEmpresaController.java

public void atualizar() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {//ww  w.j  a  v  a  2s  .  com
        s.merge(this.cat);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Dado Atualizado com Sucesso!");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    view.loadTable();
    s.close();
}

From source file:controller.CommandesController.java

@RequestMapping(value = "/addCommandes", method = RequestMethod.POST)
public String ajoutCommande(Model model, Orders order, HttpServletRequest request,
        @RequestParam(value = "history", defaultValue = "") String hist1,
        @RequestParam(value = "history2", defaultValue = "") String hist2,
        @RequestParam(value = "history3", defaultValue = "") String hist3) {
    DaoOrders dao = (DaoOrders) FactoryDao.getDao(Orders.class);
    Employee emp = (Employee) request.getSession().getAttribute("userConnecte");
    order.setEmployee(emp);//  ww  w .  ja  v a2  s  . c o m
    Date d = new Date();
    order.setDateOrders(d);
    dao.insert(order);
    List<Orders> l = new ArrayList<Orders>();
    Session s = HibernateUtil.getSession();
    s.merge(order);
    s.refresh(order);
    l.add(order);
    model.addAttribute("ordp", new Orderproduct());
    model.addAttribute("lOrder", l);
    return "addCommandes_1";
}

From source file:controller.ContatoController.java

public void atualizarContato() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {//w w  w .  j a  v a2s .com
        s.merge(this.contato);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Contato Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();

}

From source file:controller.DoceController.java

@Override
public void atualizarHerdeiro() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {/*from  w ww  . jav a 2  s.co  m*/
        s.merge(this.doce);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Dado Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();
}

From source file:controller.EmpresaController.java

@Override
public void atualizarHerdeiro() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {/*from   w w w  .  j  a v  a  2s.  co  m*/
        s.merge(this.empresa);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Dado Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();
}

From source file:controller.PessoaFisicaController.java

@Override
public void atualizarHerdeiro() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {/*from w ww .j a v a 2  s.c  o  m*/
        s.merge(this.pessoa);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Dado Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();
}

From source file:controller.ProdutoController.java

public void atualizarProduto() {
    SessionFactory sf = HibernateUtil.getSessionFactory();
    Session s = sf.openSession();
    Transaction tx = s.beginTransaction();

    try {// ww  w .j av a2s. c om
        s.merge(this.produto);
        tx.commit();
        JOptionPane.showMessageDialog(null, "Produto Atualizado com Sucesso!");
    } catch (HeadlessException e) {
        JOptionPane.showMessageDialog(null, "Erro ao atualizar os dados: " + e.getMessage());
        tx.rollback();
    }

    s.close();

}

From source file:cz.filmtit.userspace.DatabaseObject.java

License:Open Source License

/**
 * Save the properties of the DatabaseObject to the database,
 * but not the dependent objects (like matches for chunks etc.) which are not explicitly
 * included in the Hibernate mapping./*w w w.ja  v  a2s  .c o  m*/
 * @param session A database transaction in which operation is done.
 *
 */
protected synchronized void saveJustObject(Session session) {
    if (this instanceof USTranslationResult) {
        USTranslationResult tr = (USTranslationResult) this;

        if (tr.getSharedId() < 0) {
            RuntimeException e = new RuntimeException("object : ShareID lesser than zero!");

            StringBuilder errorBuilder = new StringBuilder();
            StackTraceElement[] st = e.getStackTrace();
            for (StackTraceElement stackTraceElement : st) {
                errorBuilder.append(stackTraceElement.toString());
                errorBuilder.append("\n");
            }

            logger.error(errorBuilder.toString());

            throw new RuntimeException("session id < 0");
        }
    }

    if (databaseId == Long.MIN_VALUE) {
        session.save(this);
    } else {
        session.merge(this);
    }
}

From source file:dao.ActeDecesDAOImp.java

@Override
public boolean updateDeclaration(DeclarationDeces acte) {
    Transaction tx = null;/* ww w  .  j  a  va  2 s.  co  m*/
    Session session = null;
    boolean flag = false;
    try {
        session = HibernateUtil.getSessionFactory();
        tx = session.beginTransaction();
        DeclarationDeces a = this.findById(acte.getId());

        if (a == null) {
            session.save(acte);
            flag = true;
            tx.commit();
        }
        // Sinon on est dans le cas d'une modification de l'acte : merge
        else {
            session.merge(acte);
            flag = true;
            tx.commit();
        }
    } catch (HibernateException he) {
        if (tx != null)
            tx.rollback();
        he.printStackTrace();
    } finally {
        if (session != null)
            session.close();
    }
    return flag;
}