List of usage examples for org.hibernate Session get
Object get(String entityName, Serializable id);
From source file:cn.newtouch.model.TeacherTest.java
License:Open Source License
@Test public void testUpdate6() { Session session = HibernateUtil.getSession(); session.beginTransaction();//from w w w. j av a2s. c o m Student s = (Student) session.get(Student.class, 1L); s.setName("zhangsan6"); session.getTransaction().commit(); s.setName("z4"); Session session2 = HibernateUtil.getSession(); session2.beginTransaction(); // ? session2.merge(s); session2.getTransaction().commit(); }
From source file:co.com.edu.udea.micine.DAO.impl.CineDAOImpl.java
@Override public Cine obtenerCine(int id) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Cine c = (Cine) session.get(Cine.class, id); tx.commit();/* www . ja v a 2 s .c om*/ session.close(); return c; }
From source file:co.com.edu.udea.micine.DAO.impl.FormatoDAOImpl.java
@Override public Formato obtenerFormato(int id) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Formato c = (Formato) session.get(Formato.class, id); tx.commit();/* www. j a va2 s . co m*/ session.close(); return c; }
From source file:co.com.edu.udea.micine.DAO.impl.LocalidadDAOImpl.java
@Override public Localidad obtenerLocalidad(int id) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Localidad c = (Localidad) session.get(Localidad.class, id); tx.commit();//from ww w. ja v a 2 s.c o m session.close(); return c; }
From source file:co.com.edu.udea.micine.DAO.impl.OperadorDAOImpl.java
@Override public Operador buscarOperador(String cedula) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Operador o = (Operador) session.get(Operador.class, cedula); tx.commit();/*from w w w .j a v a 2 s . c o m*/ session.close(); return o; }
From source file:co.com.edu.udea.micine.DAO.impl.SocioDAOImpl.java
@Override public Socio obtenerSocio(int id) { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); Socio c = (Socio) session.get(Socio.class, id); tx.commit();/* w w w . j a va2s .c om*/ session.close(); return c; }
From source file:co.edu.udea.profarq.labcinco.dao.hibernate.impl.AbstractEntityDAO.java
public IEntityContext find(Class<? extends IEntityContext> c, Serializable primaryKey) throws LabCincoProfArqDAOException { IEntityContext entityContext = null; Session session; try {//from w ww.j av a 2s .c o m SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); session = sessionFactory.openSession(); entityContext = (IEntityContext) session.get(c, primaryKey); session.close(); } catch (Exception ex) { throw new LabCincoProfArqDAOException( String.format("Error during procedure's \"%s\" for class: %s", "Find", c.getSimpleName()), ex); } return (entityContext); }
From source file:co.utb.softeng.contactsapp.dao.impl.ContactDAOImpl.java
public Contact addCitasToContact(List<Cita> citas, Long contactId) { Session session = getSession(); Contact contact = (Contact) session.get(Contact.class, contactId); //Lado dominante es Contact contact.getCitas().addAll(citas);// w ww. ja va 2 s . co m session.saveOrUpdate(contact); return contact; }
From source file:com.abiquo.abiserver.abicloudws.InfrastructureWS.java
License:Open Source License
@Override public BasicResult forceRefreshVirtualMachineState(final VirtualMachine virtualMachine) { logger.info("Forcing refresh of the virtual machine state: {}", virtualMachine.getId()); BasicResult result = new BasicResult(); VirtualappHB virtualappHBPojo = null; Session session = null; Transaction transaction = null;//from w ww .j a va 2s .c o m try { session = HibernateUtil.getSession(); transaction = session.beginTransaction(); Query query = session.createSQLQuery(IDVIRTUALAPP_SQL_BY_VM); query.setString("id", virtualMachine.getId().toString()); Integer virtualApplianceId = (Integer) query.uniqueResult(); virtualappHBPojo = (VirtualappHB) session.get("VirtualappExtendedHB", virtualApplianceId); VirtualAppliance vapp = virtualappHBPojo.toPojo(); String virtualSystemMonitorAddress = RemoteServiceUtils.getVirtualSystemMonitorFromVA(vapp); // EventingSupport.subscribePullEventToVM(virtualMachine, virtualSystemMonitorAddress); } catch (PersistenceException e) { logger.trace("An error occurred when retrieving the VirtualSystemMonitor", e.getStackTrace()[0]); } catch (RemoteServiceException e) { logger.trace("An error occurred when contacting the VirtualSystemMonitor", e.getStackTrace()[0]); } result.setSuccess(true); return result; }
From source file:com.abiquo.abiserver.abicloudws.InfrastructureWSTest.java
License:Mozilla Public License
private VirtualMachine getVirtualImageFromDb(int virtualMachineId) { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); Session session = sessionFactory.openSession(); Transaction transaction = session.getTransaction(); transaction.begin();/*from w ww . ja v a 2 s . c om*/ VirtualmachineHB virtualMachinePojo = (VirtualmachineHB) session.get(VirtualmachineHB.class, virtualMachineId); VirtualMachine virtualMachine = new VirtualMachine(); virtualMachine.setCpu(virtualMachinePojo.getCpu()); virtualMachine.setDescription(virtualMachinePojo.getDescription()); virtualMachine.setHd(virtualMachine.getHd()); virtualMachine.setHighDisponibility(virtualMachinePojo.getHighDisponibility() != 0); virtualMachine.setId(virtualMachinePojo.getIdVm()); virtualMachine.setName(virtualMachinePojo.getName()); virtualMachine.setRam(virtualMachinePojo.getRam()); State state = new State(); state.setId(virtualMachinePojo.getState().getIdState()); state.setDescription(virtualMachinePojo.getState().getDescription()); virtualMachine.setState(state); virtualMachine.setUUID(virtualMachinePojo.getUuid()); virtualMachine.setVdrpIP(virtualMachinePojo.getVdrpIp()); virtualMachine.setVdrpPort(virtualMachinePojo.getVdrpPort()); VirtualimageHB virtualimagePojo = virtualMachinePojo.getImage(); VirtualImage virtualImage = new VirtualImage(); virtualImage.setName(virtualimagePojo.getName()); virtualImage.setPath(virtualimagePojo.getPathName()); virtualMachine.setVirtualImage(virtualImage); // Setting the hypervisor HypervisorHB hypervisorPojo = virtualMachinePojo.getHypervisor(); HyperVisor hypervisor = new HyperVisor(); hypervisor.setIp(hypervisorPojo.getIp()); hypervisor.setPort(hypervisorPojo.getPort()); hypervisor.setName(hypervisorPojo.getType().getName()); virtualMachine.setAssignedTo(hypervisor); transaction.commit(); return virtualMachine; }