List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:com.mercatis.lighthouse3.persistence.users.hibernate.GroupRegistryImplementation.java
License:Apache License
@Override public void update(Group entityToUpdate) { Session session = unitOfWork.getCurrentSession(); Set<UserCodeRegistration> regs = entityToUpdate.getUserCodes(); for (UserCodeRegistration userCode : regs.toArray(new UserCodeRegistration[0])) { if (existsUserCode(userCode.getUserCode())) { regs.remove(userCode);//from www. j a v a 2 s.c om userCode = (UserCodeRegistration) session.merge(userCode); regs.add(userCode); } } super.update(entityToUpdate); }
From source file:com.minhafazenda.model.MfAuditoriaConfiguracaoModel.java
public String update(MfAuditoriaConfiguracao obj) { Session objSession = this.objSessionFactory.openSession(); Transaction objTransaction = objSession.beginTransaction(); try {//from w ww . ja v a 2 s. c om objSession.merge(obj); objTransaction.commit(); } catch (Exception e) { msg = e.getMessage(); objTransaction.rollback(); } objSession.close(); return msg; }
From source file:com.minhafazenda.model.VacinaAnimalModel.java
public String update(VacinaAnimal obj) { //Abre um sesso Session objSession = this.objSessionFactory.openSession(); //Inicia uma transao dentro da sesso aberta Transaction objTransaction = objSession.beginTransaction(); try {/*w w w.j a v a 2 s .c o m*/ //ATUALIZA o objeto, assim o hibernate persiste no bancoapagando o registro. objSession.merge(obj); //Realiza um commit do UPDATE objTransaction.commit(); } catch (Exception e) { //Caso ocorrer algum erro, mostra uma mensagem msg = e.getMessage(); //Realiza o Rollback, cancelando o UPDATE no banco de dados. objTransaction.rollback(); } //Fecha a sesso objSession.close(); //Retorna a mensagem return msg; }
From source file:com.minhafazenda.model.VacinaModel.java
public String update(Vacina obj) { //Abre um sesso Session objSession = this.objSessionFactory.openSession(); //Inicia uma transao dentro da sesso aberta Transaction objTransaction = objSession.beginTransaction(); try {//from w ww .ja v a 2 s.c o m //ATUALIZA o objeto, assim o hibernate persiste no bancoapagando o registro. objSession.merge(obj); //Realiza um commit do UPDATE objTransaction.commit(); } catch (Exception e) { //Caso ocorrer algum erro, mostra uma mensagem msg = e.getMessage(); //Realiza o Rollback, cancelando o UPDATE no banco de dados. objTransaction.rollback(); } //Fecha a sesso objSession.close(); //Retorna a mensagem return msg; }
From source file:com.model.dao.EmployeeDao.java
public static boolean addEmploye(Employee e) { boolean result = false; Session session = HibernateUtil.getSessionFactory().openSession(); session.setCacheMode(CacheMode.IGNORE); Transaction tx = null;//w ww. j a v a 2s . c om try { tx = session.beginTransaction(); session.merge(e); tx.commit(); result = true; } catch (HibernateException ex) { if (tx != null) { tx.rollback(); result = false; } ex.printStackTrace(); } finally { session.close(); } return result; }
From source file:com.mtech.springsecurity.dao.AccountsDaoImpl.java
public NorminalAccounts saveNorminalAccounts(NorminalAccounts norminalAccounts) { Session session1 = getSession(); if (norminalAccounts.getId() != null) { session1.merge(norminalAccounts); } else {/*w w w. j a v a 2 s. com*/ session1.persist(norminalAccounts); } return norminalAccounts; }
From source file:com.mtech.springsecurity.dao.AccountsDaoImpl.java
public Accounts saveAccounts(Accounts accounts) { Session session1 = getSession(); if (accounts.getId() == null) { session1.persist(accounts);//from ww w . j a va 2 s . c o m } else { session1.merge(accounts); } return accounts; }
From source file:com.mtech.springsecurity.dao.BankDaoImpl.java
public BankBranch saveBankBranch(BankBranch bankBranch) { Session bankBranchSession = getSession(); if (bankBranch.getId() == null) { bankBranchSession.saveOrUpdate(bankBranch); } else {/*from w ww .j a v a 2 s.c om*/ bankBranchSession.merge(bankBranch); } bankBranchSession.flush(); return bankBranch; }
From source file:com.music.dao.impl.GenericDAOImpl.java
@Transactional(propagation = Propagation.REQUIRES_NEW) public boolean update(E e) { // If e is not null, continue updating e if (e != null) { // Get current session Session session = sessionFactory.getCurrentSession(); // Update (or merge to existing) e to session session.merge(e); return true; }/*from w w w .j a va 2 s .c o m*/ return false; }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
public Object saveEntity(Object entity) throws SaveException { if (entity != null) { Serializable pk = null;/*from w w w. j ava 2 s . c om*/ if (entity instanceof CoreInfo) { pk = ((CoreInfo) entity).getId(); } if (entity instanceof CoreBaseInfo) { CoreBaseInfo cbInfo = (CoreBaseInfo) entity; cbInfo.setLastUpdateDate(new Date()); } if (BaseUtil.isEmpty(pk)) { pk = addNewEntity(entity); } else { checkLicense(entity); Session sesion = getCurrentSession(); boolean toUpTree = false; if (entity instanceof CoreBaseTreeInfo) { CoreBaseTreeInfo curTreeInfo = (CoreBaseTreeInfo) entity; CoreBaseTreeInfo dbTreeInfo = (CoreBaseTreeInfo) sesion.get(entity.getClass(), pk); toUpTree = isEquals(curTreeInfo.getName(), dbTreeInfo.getName()) || isEquals(curTreeInfo.getNumber(), dbTreeInfo.getNumber()); } if (toUpTree) { updateTreeData(sesion, (CoreBaseTreeInfo) entity); } else { sesion.merge(entity); } sesion.flush(); } if (pk != null) { return entity; } } return null; }