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.proj.tasker.dao.impl.logRelDAO.java

@Override
public void logTar(Logrealizacao log) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*ww  w  . j  a  v a2  s . c  om*/
        session.getTransaction().begin();
        session.save(log);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Inserir: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.proj.tasker.dao.impl.PessoaDAO.java

@Override
public void inserirPessoa(Pessoa pessoa) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/* ww w.  ja v  a  2s .co  m*/
        session.getTransaction().begin();
        session.save(pessoa);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Inserir: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.proj.tasker.dao.impl.ProjetoDAO.java

@Override
public void cadastrarProjeto(Projeto proj) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from   w  ww .j a va2s . co  m
        session.getTransaction().begin();
        session.save(proj);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Cadastrar: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.proj.tasker.dao.impl.TarefaDAO.java

@Override
public void cadastrarTarefa(Tarefa tar) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//w  w  w.  j av a 2s.c  om
        session.getTransaction().begin();
        session.save(tar);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Cadastrar: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.proj.tasker.dao.impl.TelefoneDAO.java

@Override
public void inserirTelefone(Telefone tel) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from   w ww  . j a va 2s  . c o  m
        session.getTransaction().begin();
        session.save(tel);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Inserir: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.proj.tasker.dao.impl.UsuarioDAO.java

@Override
public void inserirUsuario(Usuario usuario) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from w w w  .  j av a 2s.  c  om
        session.getTransaction().begin();
        session.save(usuario);
        session.getTransaction().commit();
    } catch (Exception e) {
        System.out.println("Erro ao Inserir: " + e.getMessage());
        session.getTransaction().rollback();
    }
}

From source file:br.com.projetoweb.model.dao.LivroDAOImp.java

public void save(Livro livro) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = session.beginTransaction();
    session.save(livro);
    t.commit();//from  w w  w .  j  a v a2s .  c  o m
}

From source file:br.com.pucminas.debt.dao.impl.AtualizacaoDAOImpl.java

@Override
public void salvar(Atualizacao atualizacao) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = null;/*w w w  . j  av a  2 s  . c  o m*/
    try {
        t = session.beginTransaction();
        atualizacao.setId(0);
        session.save(atualizacao);
        session.getTransaction().commit();
    } catch (HibernateException e) {
        if (t != null) {
            t.rollback();
        }
    } finally {
        session.close();
    }
}

From source file:br.com.pucminas.debt.dao.impl.MetricaDAOImpl.java

@Override
public void salvar(Metrica metrica) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = null;/*from  w ww  .ja va2  s  .c o m*/
    try {
        t = session.beginTransaction();
        metrica.setId(0);
        session.save(metrica);
        session.getTransaction().commit();
    } catch (HibernateException e) {
        if (t != null) {
            t.rollback();
        }
    } finally {
        session.close();
    }
}

From source file:br.com.pucminas.debt.dao.impl.ValorMetricaDAOImpl.java

@Override
public void salvar(List<ValorMetrica> valoresMetrica) {

    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction t = null;/*from   w  w w.j  a  v  a 2  s. c  om*/
    try {
        session.beginTransaction();

        for (ValorMetrica val : valoresMetrica) {
            if (val.getValor() != null) {
                val.setId(0);
                session.save(val);
                session.flush();
                session.clear();
            }
        }
        session.getTransaction().commit();

    } catch (HibernateException e) {
        if (t != null) {
            t.rollback();
        }
    } finally {
        session.close();
    }
}