Example usage for org.hibernate Session saveOrUpdate

List of usage examples for org.hibernate Session saveOrUpdate

Introduction

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

Prototype

void saveOrUpdate(Object object);

Source Link

Document

Either #save(Object) or #update(Object) the given instance, depending upon resolution of the unsaved-value checks (see the manual for discussion of unsaved-value checking).

Usage

From source file:AdminSystemClasses.AtmDB.java

public static boolean edit(EditATM edit) {

    Session sf = DB.getSession();
    Transaction tx = sf.beginTransaction();

    BankATM bank = new BankATM();

    BankBranch bb = (BankBranch) sf.load(BankBranch.class, edit.getBranchid());
    bank.setId(edit.getAtmId());//w w w  .j  av a  2s.  c  o m
    bank.setBankbranch(bb);
    if (edit.getTill().intValue() < 0) {
        return false;
    } else {
        bank.setTill(edit.getTill());
    }
    sf.saveOrUpdate(bank);
    tx.commit();
    return true;
}

From source file:Anbulategi.bajaTxostenaDAOHibernate.java

public void save(bajaTxostena baja) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {//ww w . j ava2 s . c o  m
        session.beginTransaction();
        session.saveOrUpdate(baja);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }

}

From source file:Anbulategi.ErrezetaDAOHibernate.java

public void save(Errezeta errezeta) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {//from   w  w  w.  ja va 2 s . c  o  m
        session.beginTransaction();
        session.saveOrUpdate(errezeta);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }

}

From source file:Anbulategi.EspezialistaDAOHibernate.java

@Override
public void save(Espezialista espezialista) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {//  www .java 2s . c om
        session.beginTransaction();
        session.saveOrUpdate(espezialista);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }
}

From source file:Anbulategi.GaixoaDAOHibernate.java

public void save(Gaixoa gaixo) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {/*from  w ww  .  j  a v  a2 s .c  o  m*/
        session.beginTransaction();
        session.saveOrUpdate(gaixo);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }
}

From source file:Anbulategi.HistorialDAOHibernate.java

@Override
public void save(Historial historiala) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {/* w  ww  . ja  v a2  s. c o  m*/
        session.beginTransaction();
        session.saveOrUpdate(historiala);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }
}

From source file:Anbulategi.IdazkariaDAOHibernate.java

@Override
public void save(Idazkaria idazkari) {
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {// w ww  .ja  v a2  s . c  o  m
        session.beginTransaction();
        session.saveOrUpdate(idazkari);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }
}

From source file:Anbulategi.SendagileaDAOHibernate.java

@Override
public void save(Sendagilea sendagile) {

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    try {//from  ww  w .ja v a  2 s  .  co  m
        session.beginTransaction();
        session.saveOrUpdate(sendagile);
        session.getTransaction().commit();
    } catch (Exception ex) {
        ex.printStackTrace();
        session.getTransaction().rollback();
    }
}

From source file:angeldx.manager.EstudianteManager.java

public boolean registrar(Estudiante est) {
    Session session = HibernateUtil.openSession();
    Transaction tran = null;/* ww  w.j ava  2s.  co m*/
    try {
        tran = session.getTransaction();
        tran.begin();
        session.saveOrUpdate(est);
        tran.commit();
    } catch (Exception e) {
        if (tran != null) {
            tran.rollback();
        }
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return true;
}

From source file:appointment.data.ObjectFactory.java

public Object updateDataResource(Object resource) {
    Session session = factory.openSession();
    Transaction tx = session.beginTransaction();
    Object mergedOne = session.merge(resource);
    session.saveOrUpdate(mergedOne);
    tx.commit();/*w ww  .j  ava  2s.c  om*/

    return mergedOne;
}