List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:com.autentia.intra.dao.hibernate.HibernateManagerBase.java
License:Open Source License
public ITransferObject merge(ITransferObject obj) throws DataAccException { Serializable pk = obj.getId(); if (pk == null) return obj; try {/*www . j a va 2 s . c o m*/ Session session = null; session = HibernateUtil.currentSession(); session.beginTransaction(); log.debug("objeto con clave '" + pk + "' recuperado para mezcla"); obj = (ITransferObject) session.merge(obj); try { session.getTransaction().commit(); log.debug("objeto con clave '" + pk + "' correctamente mezclado"); } catch (HibernateException ex) { session.getTransaction().rollback(); session.clear(); } } catch (Exception ex) { String msg = "Error mezclando el objeto '" + obj + "' con clave primaria '" + pk + "'"; log.debug("error mezclando el objeto '" + pk + "': " + msg); throw new DataAccException(msg, ex); } return obj; }
From source file:com.autentia.tnt.dao.hibernate.HibernateManagerBase.java
License:Open Source License
/** * Actualiza una objeto de negocio en base de datos * * @param obj el objeto de negocio a actualizar *//*from w ww .j a v a 2 s .c om*/ public void update(ITransferObject obj, Serializable pk) throws DataAccException { log.debug("update"); Session session = null; try { session = HibernateUtil.getSessionFactory().getCurrentSession(); obj.setUpdateDate(new Date()); session.merge(obj); log.debug("objeto con clave '" + pk + "' correctamente actualizado"); if (this.cacheable) HibernateManagerBase.removeCacheFor(obj.getClass().getName()); } catch (Exception ex) { String msg = "Error actualizando el objeto '" + obj + "' con clave primaria '" + pk + "'"; log.debug("error actualizando el objeto '" + pk + "': " + msg); throw new DataAccException(msg, ex); } }
From source file:com.bakeryfactory.cadastros.servidor.PessoaDetalheAction.java
License:Open Source License
private Response update(Object inputPar, UserSessionParameters userSessionPars, HttpServletRequest request, HttpServletResponse response, HttpSession userSession, ServletContext context) { Session session = null; try {//from w ww . j av a 2 s . c om Object[] pars = (Object[]) inputPar; PessoaVO pessoa = (PessoaVO) pars[2]; PessoaFisicaVO pessoaFisica = (PessoaFisicaVO) pars[3]; PessoaJuridicaVO pessoaJuridica = (PessoaJuridicaVO) pars[4]; List<PessoaContatoVO> listaContato = (Vector) pars[5]; List<PessoaEnderecoVO> listaEndereco = (Vector) pars[6]; List<PessoaTelefoneVO> listaTelefone = (Vector) pars[7]; session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); updateOnTipoPessoa(pessoa, session, pessoaFisica, pessoaJuridica); toSetTipoPessoa(pessoa, pessoaFisica, pessoaJuridica); pessoa.setListaContato(listaContato); pessoa.setListaEndereco(listaEndereco); pessoa.setListaTelefone(listaTelefone); session.merge(pessoa); session.getTransaction().commit(); return new VOResponse(pessoa); } catch (Exception ex) { ex.printStackTrace(); if (session != null) { session.getTransaction().rollback(); } return new ErrorResponse(ex.getMessage()); } finally { try { if (session != null) { session.close(); } } catch (Exception ex1) { ex1.printStackTrace(); } } }
From source file:com.baomidou.hibernateplus.dao.impl.DaoImpl.java
License:Open Source License
@Override public boolean updateBatch(List<P> list, int size) { Assert.notEmpty(list);/* www .j a va 2 s.c o m*/ try { Session session = HibernateUtils.getSession(masterSession(), isCurrent()); for (int i = 0; i < list.size(); i++) { session.merge(list.get(i)); if (i % size == 0) { session.flush(); session.clear(); } } } catch (Exception e) { logger.warn("Warn: Unexpected exception. Cause:" + e); return false; } return true; }
From source file:com.bolao.persistencia.dao.ApostadorDAO.java
public String refresh(Apostador apostador) { try {//ww w . j av a 2s .com Session session = HibernateFactory.getSessionFactory(); session.beginTransaction(); session.merge(apostador); session.getTransaction().commit(); session.close(); } catch (Exception e) { return HibernateFactory.FALHA; } return HibernateFactory.SUCESSO; }
From source file:com.bolao.persistencia.dao.GrupoDAO.java
public String refresh(Grupo grupo) { try {/*w w w .j ava 2 s . co m*/ Session session = HibernateFactory.getSessionFactory(); session.beginTransaction(); session.merge(grupo); session.getTransaction().commit(); session.close(); } catch (Exception e) { return HibernateFactory.FALHA; } return HibernateFactory.SUCESSO; }
From source file:com.bolao.persistencia.dao.TimeDAO.java
public String refresh(Time time) { try {/*from ww w.j a va 2s.c om*/ Session session = HibernateFactory.getSessionFactory(); session.beginTransaction(); session.merge(time); session.getTransaction().commit(); session.close(); } catch (Exception ex) { return HibernateFactory.FALHA; } return HibernateFactory.SUCESSO; }
From source file:com.chingo247.structureapi.persistence.service.AbstractService.java
License:Open Source License
protected T save(T t) { Session session = null; Transaction tx = null;//from w w w . j a v a 2 s . co m try { session = HibernateUtil.getSession(); tx = session.beginTransaction(); t = (T) session.merge(t); tx.commit(); } catch (HibernateException e) { try { tx.rollback(); } catch (HibernateException rbe) { Logger.getLogger(AbstractService.class.getName()).log(Level.SEVERE, "Couldnt roll back transaction", rbe); } throw e; } finally { if (session != null) { session.close(); } } return t; }
From source file:com.chingo247.structureapi.persistence.service.StructureService.java
License:Open Source License
public Structure save(Structure structure) { Session session = null; Transaction tx = null;//from w ww.j a v a 2 s. c o m try { session = HibernateUtil.getSession(); tx = session.beginTransaction(); structure = (Structure) session.merge(structure); tx.commit(); } catch (HibernateException e) { try { tx.rollback(); } catch (HibernateException rbe) { Logger.getLogger(AbstractService.class.getName()).log(Level.SEVERE, "Couldnt roll back transaction", rbe); } throw e; } finally { if (session != null) { session.close(); } } return structure; }
From source file:com.chingo247.structureapi.persistence.service.ValidationService.java
License:Open Source License
private void setRemovedAfter(World world, Timestamp timestamp) { Session session = null; Transaction tx = null;/*ww w. j a va 2s .c o m*/ try { session = HibernateUtil.getSession(); tx = session.beginTransaction(); QStructure qct = QStructure.structure; JPQLQuery query = new HibernateQuery(session); List<Structure> structures = query .from(qct).where( qct.logEntry().autoremoved.eq(Boolean.FALSE) .and(qct.location().worldUUID.eq(world.getUID())).and(qct.logEntry().completedAt .after(timestamp).or(qct.logEntry().removedAt.after(timestamp)))) .list(qct); if (!structures.isEmpty()) { StructureAPI.print( "World " + world + " contains " + structures.size() + " that have an invalid status"); Iterator<Structure> it = structures.iterator(); RegionManager manager = WorldGuardUtil.getRegionManager(Bukkit.getWorld(world.getName())); while (it.hasNext()) { Structure structure = it.next(); if (!manager.hasRegion(structure.getStructureRegion())) { StructureAPI.print("Structure #" + structure.getId() + " was removed after last save"); reclaim(structure); StructureAPI.print("Reclaimed region: " + structure.getStructureRegion()); } // If structure was completed after world save if (timestamp.getTime() < structure.getLog().getCompletedAt().getTime()) { structure.setState(State.STOPPED); structure.getLog().setCompletedAt(null); } else { structure.setState(State.COMPLETE); } structure.getLog().setRemovedAt(null); session.merge(structure); } manager.save(); tx.commit(); } } catch (HibernateException e) { try { if (tx != null) { tx.rollback(); } } catch (HibernateException rbe) { java.util.logging.Logger.getLogger(AbstractService.class.getName()).log(Level.SEVERE, "Couldnt roll back transaction", rbe); } throw e; } catch (StorageException ex) { Logger.getLogger(ValidationService.class.getName()).log(Level.SEVERE, null, ex); } finally { if (session != null) { session.close(); } } }