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:automatedbillingsoftware_DA.ChallanDA.java

public ChallanGenerated saveChallanGen(ChallanGenerated challan) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    challan.setStatus(1);/*from  w  ww .  j a  v  a2  s  .c  o m*/
    session.saveOrUpdate(challan);
    beginTransaction.commit();

    return challan;
}

From source file:automatedbillingsoftware_DA.InvoiceReport_DA.java

public InvoiceReport saveInvoiceReport(InvoiceReport invReport) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.saveOrUpdate(invReport);
    beginTransaction.commit();//from w  w w  . j  a v  a2  s .c o m

    return invReport;
}

From source file:automatedbillingsoftware_DA.Products_DA.java

public Products addProducts(Products prod) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.saveOrUpdate(prod);
    beginTransaction.commit();/*from   w  ww.  j  a v  a 2 s  .c  o m*/
    return prod;
}

From source file:automatedbillingsoftware_DA.User_DA.java

public Users addUser(Users users) {
    SessionFactory sessionFactory = HibernateUtils.getLocSessionFactory();
    Session session = sessionFactory.getCurrentSession();
    Transaction beginTransaction = session.beginTransaction();
    session.saveOrUpdate(users);
    beginTransaction.commit();//from  ww  w.j a v a 2s. c o  m
    return users;
}

From source file:baking.dao.BaseDao.java

License:Open Source License

public void saveOrUpdate(Object obj) {
    try {/* w  ww  .  j  a  va 2 s  . co  m*/
        Session session = getSession();
        session.saveOrUpdate(obj);
    } catch (RuntimeException re) {
        throw re;
    }
}

From source file:bean.ajouterCommentaire.java

public String soumettreCommentaire(Restaurant pResto) {

    FacesContext facesContext = FacesContext.getCurrentInstance();
    HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true);
    this.membre = (Membre) session.getAttribute("membreConnecte");
    this.restaurant = pResto;
    Date today = new Date();
    this.datecreation = today;

    Transaction tx = null;//w w  w  .j a  v  a 2s  .c o m
    Session nsession = null;
    try {
        nsession = HibernateUtil.getSessionFactory().openSession();

        Commentaire unComm = new Commentaire();
        unComm.setContenu(this.contenu);
        unComm.setDatecreation(today);
        unComm.setMembre(this.membre);
        unComm.setRestaurant(this.restaurant);
        unComm.setNote(this.note);

        /* SMembre.setEmail(email);
         SMembre.setMpd(Mdp);
         typeMemUtil TypeUtil = new typeMemUtil();
         Typemembre typeMem = TypeUtil.getType(1);
         typeMem.setTypemem("membre");
         SMembre.setRestoPref(1);
         SMembre.setTypemembre(typeMem);
         SMembre.setTypecuisinePref(1);*/

        tx = nsession.beginTransaction();
        nsession.saveOrUpdate(unComm);
        tx.commit();
        nsession.close();
        return "ficheRestaurant?faces-redirect=true";
    } catch (Exception e) {
        tx.rollback();
        e.printStackTrace();
    }
    nsession.close();
    return null;
}

From source file:biomart.DAO.CommonDAO.java

public String addOrUpdateDetails(Object o) {

    Session session = Util.getSessionFactory().openSession();
    Transaction t = null;/*w  w w .java 2 s .  c  o  m*/
    try {
        t = session.beginTransaction();
        session.saveOrUpdate(o);
        t.commit();
    } catch (HibernateException e) {
        if (t != null) {
            t.rollback();
        }
        e.printStackTrace();
        return "fail";
    } finally {
        session.close();
    }
    return "success";
}

From source file:bookstore.dao.generic.GenericDAOImpl.java

public void save(T entity) {
    Session hibernateSession = this.getSession();
    hibernateSession.saveOrUpdate(entity);
}

From source file:br.cnec.fcsl.exemplo.dao.GenericDao.java

public void salvar(T entidade) {
    Session session = getSession();
    session.getTransaction().begin();/*from  w ww  .  j ava  2s .  com*/
    session.saveOrUpdate(entidade);
    session.getTransaction().commit();
}

From source file:br.com.apprestaurante.dao.CategoriaProdutoDao.java

public void salvar(CategoriaProduto categoriaProduto) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction transacao = null;//from   w  w  w.  j a  va 2  s.  c  om

    try {
        transacao = session.beginTransaction();
        session.saveOrUpdate(categoriaProduto);
        transacao.commit();
    } catch (HibernateException e) {
        if (transacao != null) {
            transacao.rollback();
        }
        e.printStackTrace();
        throw new HibernateException(e.getMessage());
    } finally {
        session.close();
    }
}