List of usage examples for org.hibernate Session save
Serializable save(Object object);
From source file:br.com.livraria.dao.FuncionarioDAO.java
public void salvar(Funcionario funcionario) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;/*w w w . jav a 2s . c om*/ try { transacao = sessao.beginTransaction(); sessao.save(funcionario); transacao.commit(); } catch (RuntimeException ex) { if (transacao != null) { transacao.rollback(); } throw ex; } finally { sessao.close(); } }
From source file:br.com.livraria.dao.ItemDAO.java
public void salvar(Item item) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;//from w ww. j a v a 2 s . c om try { transacao = sessao.beginTransaction(); sessao.save(item); transacao.commit(); } catch (RuntimeException ex) { if (transacao != null) { transacao.rollback(); } throw ex; } finally { sessao.close(); } }
From source file:br.com.livraria.dao.VendaDAO.java
public Long salvar(Venda venda) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null;/*from www .j av a 2s.c o m*/ Long codigo = null; try { transacao = sessao.beginTransaction(); codigo = (Long) sessao.save(venda); transacao.commit(); } catch (RuntimeException ex) { if (transacao != null) { transacao.rollback(); } throw ex; } finally { sessao.close(); } return codigo; }
From source file:br.com.ln.dao.GenericDao.java
/** * * @param obj save a obj// w w w.ja v a 2 s.c o m * @param strDbName * */ public static void saveObject(Object obj) { Session session = null; Transaction tx; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); tx = session.beginTransaction(); session.save(obj); tx.commit(); } catch (HibernateException ex) { logger.error("Problemas na gravao : " + ex.getMessage()); } finally { if (session != null && session.isOpen()) { session.close(); } } }
From source file:br.com.ln.hibernate.Postgress.java
/** * * @param obj save a obj/* w w w . j a va 2 s . c om*/ * @param strDbName * */ public static void saveObject(Object obj) { Session session = null; try { session = SessionFactoryDbName.getCurrentSessionByName(VarComuns.strDbName); Transaction tx = session.beginTransaction(); session.save(obj); tx.commit(); } finally { if (session != null && session.isOpen()) { session.close(); } } }
From source file:br.com.lsi.ordemservico.dao.DAOGeneric.java
@Override public void salvar(T t) throws DAOException { Session sessao = PersistenceUtil.getSessionFactory().openSession(); try {/*from w ww . j a v a 2s . c om*/ sessao.getTransaction().begin(); sessao.save(t); sessao.getTransaction().commit(); } catch (Exception e) { sessao.getTransaction().rollback(); e.printStackTrace(); throw new DAOException("Erro ao Salvar no BD"); } finally { sessao.close(); } }
From source file:br.com.machina.verbum.Main.java
License:Apache License
private static void addAdministratorUser() { AnnotationConfiguration configuration = new AnnotationConfiguration(); configuration.configure();// ww w . j a va2s . c om SessionFactory sessionFactory = configuration.buildSessionFactory(); Session session = null; Transaction transaction = null; try { session = sessionFactory.openSession(); transaction = session.beginTransaction(); User user = new User(); user.setName(ask("Please type your name:")); user.setLogin(ask("Please type your login:")); final String password = ask("Please type your password:"); user.setEmail(ask("Please type your e-mail:")); Sha1PasswordEncrypter encrypter = new Sha1PasswordEncrypter(); user.setPassword(encrypter.encrypt(password)); user.setAdministrator(true); session.save(user); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } finally { if (session != null) { session.close(); } sessionFactory.close(); } }
From source file:br.com.mandado.dao.BairroDAO.java
/** * * @param bairro//w w w .j av a 2s.c om */ public void salvar(Bairro bairro) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null; try { transacao = sessao.beginTransaction(); sessao.save(bairro); transacao.commit(); } catch (RuntimeException ex) { if (transacao != null) { transacao.rollback(); } throw ex; } finally { sessao.close(); } }
From source file:br.com.mandado.dao.MandadoDAO.java
/** * * @param mandado/*ww w. ja va2s.c o m*/ */ public void salvar(Mandado mandado) { Session sessao = HibernateUtil.getSessionFactory().openSession(); Transaction transacao = null; try { transacao = sessao.beginTransaction(); sessao.save(mandado); transacao.commit(); } catch (RuntimeException ex) { if (transacao != null) { transacao.rollback(); } throw ex; } finally { sessao.close(); } }
From source file:br.com.nfsconsultoria.nfsuporte.dao.GenericDAO.java
public void salvar(Entidade entidade) { Session sesao = HibernateUtil.getFabricaDeSessoes().openSession(); Transaction transacao = null;//from w ww . ja v a 2s.com try { transacao = sesao.beginTransaction(); sesao.save(entidade); transacao.commit(); } catch (RuntimeException erro) { if (transacao != null) { transacao.rollback(); } throw erro; } finally { sesao.close(); } }