List of usage examples for org.hibernate Session load
void load(Object object, Serializable id);
From source file:Beans.ajusteProfesorInfo.java
public void insertar_ajuste() throws ClassNotFoundException, IOException { System.out.println("Entro al ajuste"); int Codigo_Dispo = 0, codigo_dispoUsu = 0; codigo_dispoUsu = Secuencia.seque("select max(cod_dispousu) from dispo_usuario"); Codigo_Dispo = Secuencia.seque("select max(cod_dis) from disponibilidad"); System.out.println("codigo dis : " + codigo_dispoUsu); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); Profesor profe = null;// w ww . j a v a 2s .c o m profe = (Profesor) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("profesor"); Usuario temp = (Usuario) session.load(Usuario.class, new BigDecimal(Integer.parseInt(profe.getPege_id()))); Usuario temp2 = (Usuario) session.load(Usuario.class, new BigDecimal(1)); t.commit(); Disponibilidad dispo = new Disponibilidad(); dispo.setCodDis(new BigDecimal(Codigo_Dispo)); dispo.setFechaInicial(fecha_inicial); dispo.setFechaFinal(fecha_final); dispo.setNumHoras(new BigDecimal(Integer.parseInt(Cantidad_horas))); dispo.setRango(new BigDecimal(Integer.parseInt(RamgoHora))); dispo.setPeriodo(new BigDecimal(periodo)); dispo.setEstado("A"); dispo.setHorasCumplidas(new Long(0)); System.out.println("----"); boolean CrearDispo = Insert_Dispo(dispo); System.out.println("---------" + CrearDispo); if (CrearDispo) { System.out.println("creo dispo cod : " + codigo_dispoUsu); DispoUsuario dispo_usu = new DispoUsuario(); dispo_usu.setCodDispousu(new BigDecimal(codigo_dispoUsu)); dispo_usu.setDisponibilidad(dispo); dispo_usu.setUsuarioByProfesor(temp); dispo_usu.setUsuarioByAdmon(temp2); System.out.println("::::: " + dispo.toString()); boolean dis_usu = InsertDispo_Usu(dispo_usu); System.out.println("--: " + dis_usu); if (dis_usu) { boolean dispo_dias = Insert_Dias(dispo, Dias); System.out.println("-- 2 : " + dispo_dias); if (dispo_dias) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Ok", "")); FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("Datos_ajuste"); FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("Dias_ajuste"); FacesContext.getCurrentInstance().getExternalContext().redirect("ValidarProfesor.xhtml"); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Error Comunicarce Con el Administrador", "")); } } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Error Comunicarce Con el Administrador", "")); } } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Error Comunicarce Con el Administrador", "")); } }
From source file:Beans.AsiganarDirector.java
public void guardar() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); ArrayList<UsuarioProyecto> pro = new ArrayList(); try {/* w ww .ja va 2 s . c o m*/ ProyectosModelo temp2 = null; Profesor p = null; p = (Profesor) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("profesor"); boolean r = false; Proyectos proyec = null; for (int i = 0; i < pro2.size(); i++) { temp2 = (ProyectosModelo) pro2.get(i); if (temp2.isEstado() == true) { ArrayList<UsuarioProyecto> list_U = new ArrayList(); UsuarioProyecto usu = new UsuarioProyecto(); list_U = (ArrayList) session.createQuery("select us from UsuarioProyecto us inner join " + " us.proyectos p where p.codigoProyecto=" + temp2.getCod_pro()).list(); usu = list_U.get(0); Usuario u = (Usuario) session.load(Usuario.class, new BigDecimal(Integer.parseInt(p.getPege_id()))); usu.setUsuarioByDirector(u); session.update(usu); Estados e = (Estados) session.load(Estados.class, new BigDecimal(1)); EstadoProyecto ep = new EstadoProyecto(); ep = (EstadoProyecto) session.createQuery("select e from Proyectos p " + " INNER JOIN p.estadoProyectos e where p.codigoProyecto=" + temp2.getCod_pro()) .uniqueResult(); ep.setEstados(e); session.update(ep); r = true; } } t.commit(); if (r) { FacesContext.getCurrentInstance().getExternalContext().redirect("AsignarDirector.xhtml"); } else { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", "")); } } catch (Exception ex) { if (t != null) { t.rollback(); } } }
From source file:Beans.CalendarioAsesoriaUpdate.java
public void cargarInformacion() throws ParseException { horaI = "";/*from w w w .j a va 2s. c o m*/ horaF = ""; nombre_proyecto = ""; Estudiante = ""; porcentaje = ""; detalle_Asesoria = ""; list_tareas.clear(); String cod = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap() .get("Codigo_asesoria"); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); Transaction t = session.beginTransaction(); DetalleAsesoria d = new DetalleAsesoria(); try { Asesoria a = (Asesoria) session.load(Asesoria.class, new BigDecimal(Integer.parseInt(cod))); horaI = a.getHoraIni().toString(); horaF = a.getHoraFin().toString(); Proyectos p = (Proyectos) session.load(Proyectos.class, a.getCodigoProyecto()); nombre_proyecto = p.getNombre(); porcentaje = p.getPorcentaje() + " %"; DateFormat fechaHora = new SimpleDateFormat("yyyy-MM-dd"); String convertido = fechaHora.format(a.getFechaAsesoria()); t.commit(); traerDetalle(a); traerTareas(a); } catch (Exception ex) { System.out.println("Error cargar" + ex.toString()); } }
From source file:bikerent.AddDeleteEntity.java
@Test public void testAUDEntity() { // ############################################# // ################## A D D #################### // ############################################# System.out.println("TEST INSERT: "); System.out.println("3 Customer (3 Personen) hinzufgen "); System.out.println("2 Female-, 1 Male-, 1 Child-Bike (4 Bikes) hinzufgen "); System.out.println("3 Helmets, 3 Chainlocks, 2 Trailer (8 Accessoires) hinzufgen "); Session session = sm.getSession(); addCustomer(session);//from www.ja v a 2 s. c om addBikes(session); addAccessiores(session); // Committing the change in the database. session.flush(); Transaction tx = session.beginTransaction(); tx.commit(); System.out.println(" -------------------------------------------- "); System.out.println("Anzahl Bikes: " + countBikes(session)); System.out.println("Anzahl Person: " + countPerson(session)); System.out.println("Anzahl Accessoires: " + countAccessoires(session)); System.out.println("Anzahl Items: " + countItem(session)); System.out.println(" -------------------------------------------- "); assertEquals("Count of bikes must be 4: ", 4, countBikes(session)); assertEquals("Count of person must be 3: ", 3, countPerson(session)); assertEquals("Count of accessoires must be 8: ", 8, countAccessoires(session)); assertEquals("Count of item must be 12: ", 12, countItem(session)); System.out.println(printBikes(session)); // ############################################# // ############### U P D A T E ################# // ############################################# System.out.println(); System.out.println(); System.out.println(); System.out.println("TEST UPDATE: "); System.out.println("Person mit der ID 1 (Sheldon Cooper) auslesen, umbenennen und wieder auslesen"); System.out.println(printPerson(session)); custID = getFirstPersonID(session); Object object = session.load(Person.class, custID); Person p = (Person) object; System.out.println(" -------------------------------------------- "); System.out.println("Name: " + p.GetName()); Transaction tx1 = session.beginTransaction(); p.SetName("Howard", "Wolowitz"); session.update(p); session.flush(); tx1.commit(); object = session.load(Person.class, custID); p = (Person) object; System.out.println("Neuer Name: " + p.GetName()); System.out.println(" -------------------------------------------- "); System.out.println(printPerson(session)); object = session.load(Customer.class, custID); Customer c = (Customer) object; System.out.println("Neuer Name des betroffenen CUSTOMERS (Subklasse): " + c.GetName()); System.out.println(" -------------------------------------------- "); assertEquals("Count of person must be 3: ", 3, countPerson(session)); // ############################################# // ############### D E L E T E ################# // ############################################# System.out.println(); System.out.println(); System.out.println(); System.out.println("TEST DELETE: "); System.out.println("Alle Items lschen und prfen, ob noch Bikes existieren"); System.out.println(" -------------------------------------------- "); System.out.println("Momentane Anzahl an Items: " + countItem(session)); System.out.println("Momentane Anzahl an Bikes: " + countBikes(session)); List<Item> iList = session.createQuery("from Item").list(); Transaction tx2 = session.beginTransaction(); for (Item i : iList) { session.delete(i); } session.flush(); tx2.commit(); System.out.println("Neue Anzahl an Items: " + countBikes(session)); System.out.println("Neue Anzahl an Bikes: " + countBikes(session)); System.out.println(" -------------------------------------------- "); assertEquals("Count of bikes must be 0: ", 0, countBikes(session)); }
From source file:bikerent.AddDeleteEntity.java
public void UpdateEntity() { //Selecting Student Records Session session = sm.getSession(); custID = getFirstPersonID(session);/*from www. j a v a 2 s . c om*/ Object object = session.load(Person.class, custID); Person p = (Person) object; System.out.println("Name: " + p.GetName()); Transaction tx1 = session.beginTransaction(); p.SetName("Justin", "Timberlake"); session.update(p); session.flush(); tx1.commit(); object = session.load(Person.class, custID); p = (Person) object; System.out.println("Name: " + p.GetName()); assertEquals("Count of person must be 3: ", 3, countPerson(session)); }
From source file:biomart.DAO.AdminDAO.java
public String removeUserDetails(String userName, long phoneNo) { Session session = Util.getSessionFactory().openSession(); System.out.println(userName + "" + phoneNo); String userId = new SalesmanDAO().getSalesmanId(userName, phoneNo); System.out.println(userId);//from w w w . j a v a2 s.c o m Transaction t = null; try { t = session.beginTransaction(); PersonalDetailsBean personalDetailsBean = (PersonalDetailsBean) session.load(PersonalDetailsBean.class, userId); System.out.println(personalDetailsBean.toString()); session.delete(personalDetailsBean); t.commit(); } catch (HibernateException e) { if (t != null) { t.rollback(); } e.printStackTrace(); return "fail"; } finally { session.close(); } return "success"; }
From source file:br.com.alberteije.balcao.DavController.java
License:Open Source License
public void imprimeDav() { EcfDavCabecalhoVO davCabecalho = (EcfDavCabecalhoVO) this.grid.getForm1().getVOModel().getValueObject(); try {//from w w w.j a va2 s . c om Session session = HibernateUtil.getSessionFactory().openSession(); EcfEmpresaVO empresa = (EcfEmpresaVO) session.load(EcfEmpresaVO.class, 1); HashMap parametros = new HashMap(); parametros.put("NOME_EMPRESA", empresa.getRazaoSocial()); parametros.put("CNPJ_EMPRESA", empresa.getCnpj()); parametros.put("CODIGO_DAV", davCabecalho.getId()); SessionImpl sessionImpl = (SessionImpl) session; Connection connection = sessionImpl.connection(); JasperPrint jp = JasperFillManager.fillReport("./relatorios/DAV.jasper", parametros, connection); JasperPrintManager.printPage(jp, 0, false); //JasperViewer jv = new JasperViewer(jp); //jv.viewReport(jp, false); } catch (Exception e) { e.printStackTrace(); } }
From source file:br.com.clinica.dao.ConsultaDao.java
public Consulta getConsulta(Long id_consulta) { Session ss = HibernateUtil.getSessionFactory().getCurrentSession(); return (Consulta) ss.load(Consulta.class, id_consulta); }
From source file:br.com.clinica.dao.DadosAdicionaisDao.java
@Override public DadosAdicionais getDadosAdicionais(Long id_pessoa) { Session ss = HibernateUtil.getSessionFactory().getCurrentSession(); return (DadosAdicionais) ss.load(DadosAdicionais.class, id_pessoa); }
From source file:br.com.clinica.dao.PessoaDao.java
@Override public Pessoa getPessoa(Long id_pessoa) { Session ss = HibernateUtil.getSessionFactory().getCurrentSession(); return (Pessoa) ss.load(Pessoa.class, id_pessoa); }