List of usage examples for org.hibernate Session persist
void persist(Object object);
From source file:com.pojos.RegisterUitility.java
public void PersistCustomerContact(String email, String dayPhone, String eveningPhone) { Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); Customercontact cc = new Customercontact(); cc.setCustomerEmail(email);//from w ww .j a va 2s .co m cc.setCustomerPhoneDay(dayPhone); cc.setCustomerPhoneNight(eveningPhone); s.persist(cc); s.getTransaction().commit(); }
From source file:com.pojos.ShippingUtility.java
public void PersistShipingAddr(String Addr1, String Addr2, String city, String state, String zip) { Shippingaddress sa = new Shippingaddress(); sa.setAddr1(Addr1);/*w w w . ja v a2 s .c om*/ sa.setAddr2(Addr2); sa.setCity(city); sa.setState(state); sa.setZip(zip); Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); s.persist(sa); s.getTransaction().commit(); }
From source file:com.pojos.ShippingUtility.java
public void PersistBillingAddr(String Addr1, String Addr2, String city, String state, String zip) { Billingaddress ba = new Billingaddress(); ba.setAddr1(Addr1);/*from w w w . j a v a 2s .c o m*/ ba.setAddr2(Addr2); ba.setCity(city); ba.setState(state); ba.setZip(zip); Session s = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); s.persist(ba); s.getTransaction().commit(); }
From source file:com.r3bl.dao.DiagnosticoDaoImpl.java
@Override public void addDiagnostico(Diagnostico d) { Session session = this.sessionFactory.getCurrentSession(); session.persist(d); }
From source file:com.r3bl.dao.FilaDaoImpl.java
@Override public void assignarPaciente(Paciente p, Medico m) { Session session = this.sessionFactory.getCurrentSession(); if (!checkAssignado(p.getId_paciente())) { Fila f = new Fila(); f.setMedico(m);/*from w w w.ja v a 2 s. com*/ f.setPaciente(p); f.setStatus("1"); session.persist(f); } else { logger.info("Esse usurio j tem uma consulta ativa"); } }
From source file:com.r3bl.dao.UsuarioDaoImpl.java
@Override public void addUsuario(Usuario u, String identificacao, String hospital) { try {/*from w w w. j a v a 2 s . c o m*/ Session session = this.sessionFactory.getCurrentSession(); // Salva nome do usurio pois ser diferente dependendo do tipo u.setAlias(u.getNome()); // Encripta a senha String senhaEncriptada = sec.createHash(u.getSenha()); u.setSenha(senhaEncriptada); u.setNome(identificacao); session.persist(u); if (u.getTipo().toUpperCase().equals("MEDICO")) { Medico m = new Medico(); m.setNome(u.getAlias()); m.setCrm(identificacao); m.setHospital(hospital); m.setUsuario(u); session.persist(m); } else if (u.getTipo().toUpperCase().equals("TRIAGEM")) { Triagem t = new Triagem(); t.setNome(u.getAlias()); t.setMatricula(identificacao); t.setHospital(hospital); t.setUsuario(u); session.persist(t); } logger.info("Usurio salvo com sucesso, Detalhes=" + u); } catch (Exception ex) { java.util.logging.Logger.getLogger(UsuarioDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.r3bl.dao.UsuarioDaoImpl.java
@Override public void addPaciente(Usuario u, String email, String cpf, String ts, int idade) { try {//from w w w. jav a2 s. c om Session session = this.sessionFactory.getCurrentSession(); // Gera uma senha aleatoria String senhaAleatoria = sec.randomPassword(); u.setSenha(senhaAleatoria); // Salva o nome pois para o login ser usado o cpf u.setAlias(u.getNome()); //Envia e-mail com a senha em claro mail.generateAndSendEmail(email, u.getAlias(), cpf, senhaAleatoria); // Encripta a senha String senhaEncriptada = sec.createHash(u.getSenha()); System.out.println(senhaEncriptada); u.setSenha(senhaEncriptada); u.setNome(cpf); // Persiste usuario na base session.persist(u); // Cria paciente para persistir na tabela de dados Paciente p = new Paciente(); p.setNome(u.getAlias()); p.setUsuario(u); p.setEmail(email); p.setCpf(cpf); p.setIdade(idade); p.setTs(ts); //Persiste paciente na base session.persist(p); logger.info("Usurio salvo com sucesso, Detalhes=" + u); } catch (Exception ex) { java.util.logging.Logger.getLogger(UsuarioDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ravipatel.statusserver.models.LicenseUserCompanyDao.java
License:Open Source License
public void persist(LicenseUserCompany transientInstance) { log.debug("persisting LicenseUserCompany instance"); try {/* ww w. j av a 2 s . c om*/ Session session = sessionFactory.getCurrentSession(); session.persist(transientInstance); log.debug("persist successful"); } catch (RuntimeException re) { log.error("persist failed", re); throw re; } }
From source file:com.reg.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String city = request.getParameter("city"); String state = request.getParameter("state"); String zip = request.getParameter("zip"); String country = request.getParameter("country"); String mob = request.getParameter("mob"); String org = request.getParameter("mem"); String total_pr = request.getParameter("total"); int personCount = Integer.parseInt(total_pr); Date date = new Date(); User u = new User(); u.setCity(city);//from ww w. ja v a2 s . c om u.setCountry(country); u.setD(date); u.setMobile(mob); u.setOrganization(org); u.setState(state); u.setZipcode(zip); u.setPersonCount(personCount); try { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml");//populates the data of the configuration file SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); session.persist(u); t.commit(); session.close(); request.setAttribute("sendSuccess", "block"); RequestDispatcher rd = request.getRequestDispatcher("Main.jsp"); rd.forward(request, response); } catch (Exception e) { request.setAttribute("dbError", "block"); RequestDispatcher rd = request.getRequestDispatcher("Main.jsp"); rd.forward(request, response); } }
From source file:com.rocha.rivadeneira.vera.tallerhibernate.model.ui.Starter.java
public static void main(String[] args) { System.out.println("ejemplo de hibernate"); SessionFactory sf = HibernateUtil.getSessionFactory(); Session session = sf.openSession(); List<TipoCuenta> registros = session.createQuery("SELECT obj FROM TipoCuenta obj").list(); for (TipoCuenta objeto : registros) { System.out.println(objeto); }//from ww w . j ava2 s.c o m TipoCuenta cuenta = new TipoCuenta(); cuenta.setCodigo("INB"); cuenta.setDescripcion("INVERSIONES"); Transaction tx = null; try { tx = session.beginTransaction(); session.persist(cuenta); tx.commit(); } catch (Exception e) { tx.rollback(); } registros = session.createQuery("SELECT obj FROM TipoCuenta obj").list(); for (TipoCuenta objeto : registros) { System.out.println(objeto); } session.close(); }