Example usage for org.hibernate Session save

List of usage examples for org.hibernate Session save

Introduction

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

Prototype

Serializable save(Object object);

Source Link

Document

Persist the given transient instance, first assigning a generated identifier.

Usage

From source file:br.com.railsos.os.dao.GenericDAO.java

/**
 * Mtodo Genrico Salvar Adiciona valores ao banco
 *
 * @author Rafael//w w  w .ja  v a  2  s.  co  m
 */
public void salvar(Entidade entidade) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Transaction transacao = null;

    try {
        transacao = sessao.beginTransaction();
        sessao.save(entidade);
        transacao.commit();
    } catch (RuntimeException erro) {
        if (transacao != null) {
            transacao.rollback();
        }
        throw erro;
    } finally {
        sessao.close();
    }
}

From source file:br.com.rhmanager.daoImpl.HibernateDAO.java

public void insert(Object obj) throws Exception {
    Session session = null;
    Transaction transaction = null;//ww  w. j  a v  a 2 s .co  m

    try {
        session = HibernateUtil.getSession();
        transaction = session.beginTransaction();
        session.save(obj);
        session.flush();
        transaction.commit();

    } finally {

        session.close();

    }
}

From source file:br.com.sescacre.controleAcesso.dao.CargosDAO.java

public void salvar(Cargos cargo) throws Exception {
    Session s = HibernateUtil.getSession();
    try {//from   w  ww.  j av  a 2 s. c o m
        Transaction t = s.beginTransaction();
        s.save(cargo);
        t.commit();
    } catch (Exception ex) {
        throw new SQLIntegrityConstraintViolationException();
    } finally {
        s.close();
    }
}

From source file:br.com.sescacre.controleAcesso.dao.CategoriasDao.java

public void salvar(Categorias cat) throws Exception {
    Session s = HibernateUtil.getSession();
    try {/*from  ww w .  j  a v a  2 s .c o  m*/
        Transaction t = s.beginTransaction();
        s.save(cat);
        t.commit();
    } catch (Exception ex) {
        throw new SQLIntegrityConstraintViolationException();
    } finally {
        s.close();
    }
}