List of usage examples for org.hibernate Session merge
Object merge(Object object);
From source file:org.uclab.mm.kcl.edkat.dao.ConditionDAOImpl.java
License:Apache License
/** * This function is the implementation for add new Condition * @param objCondition/*from w ww . j av a2s. c o m*/ * @return object of Condition */ public Condition addCondition(Condition objCondition) { try { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); objCondition = (Condition) session.merge(objCondition); tx.commit(); session.close(); logger.info("Condition saved successfully, Condition Details=" + objCondition); return objCondition; } catch (Exception ex) { logger.info("Error occured in saving new condition, Error Details=" + ex.getMessage()); return objCondition; } }
From source file:org.uclab.mm.kcl.edkat.dao.RuleDAOImpl.java
License:Apache License
/** * This function is the implementation for add new rule * @param objRule/*w w w . java 2 s . com*/ * @return Object of Rule */ public Rule addRule(Rule objRule) { try { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); objRule = (Rule) session.merge(objRule); tx.commit(); session.close(); logger.info("Rule saved successfully, Rule Details=" + objRule); return objRule; } catch (Exception ex) { logger.info("Error occured in saving new rule, Error Details=" + ex.getMessage()); return objRule; } }
From source file:org.uclab.mm.kcl.edkat.dao.SituationDAOImpl.java
License:Apache License
/** * This function is the implementation for add new situation * @param objSituation// www .j av a 2 s . c o m * @return object of Situations */ public Situations addSituation(Situations objSituation) { try { Situations objNewSituation = new Situations(); Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); objNewSituation = (Situations) session.merge(objSituation); tx.commit(); session.close(); logger.info("Situation saved successfully, Situation Details=" + objSituation); return objNewSituation; } catch (Exception ex) { logger.info("Error occured in saving new situation, Error Details=" + ex.getMessage()); return objSituation; } }
From source file:org.uclab.mm.kcl.edkat.dao.UserDAOImpl.java
License:Apache License
/** * This function is the implementation for add user * @param objUser// w w w.j ava2 s .co m * @return Object of User */ public User addUser(User objUser) { try { Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); session.merge(objUser); tx.commit(); session.close(); logger.info("User saved successfully, User Details=" + objUser); return objUser; } catch (Exception ex) { logger.info("Error occured in saving new user, Error Details=" + ex.getMessage()); return objUser; } }
From source file:org.workin.persistence.hibernate.v3.dao.Hibernate3PersistenceDaoImpl.java
License:Apache License
@Override public T merge(final T entity) { return getHibernateTemplate().execute(new HibernateCallback<T>() { @SuppressWarnings("unchecked") @Override/*from w w w .j av a2 s .c o m*/ public T doInHibernate(Session session) throws HibernateException, SQLException { return (T) session.merge(entity); } }); // return merge(null, entity); }
From source file:org.xerela.provider.credentials.DatabaseCredentialsPersister.java
License:Mozilla Public License
/** * Saves or updates a generic object to the database * * @param obj The generic object to save or update. * @throws PersistenceException If any issue occurred while trying save or update the generic object to the database. *///www. j a va2 s. com private void saveOrUpdate(Object obj) throws PersistenceException { try { boolean ownTransaction = TransactionElf.beginOrJoinTransaction(); SessionFactory sessionFactory = CredentialsProviderActivator.getSessionFactory(); Session currentSession = sessionFactory.getCurrentSession(); obj = currentSession.merge(obj); currentSession.saveOrUpdate(obj); if (ownTransaction) { TransactionElf.commit(); } } catch (RuntimeException e) { TransactionElf.rollback(); throw new PersistenceException(e); } }
From source file:org.xerela.provider.devices.DeviceProvider.java
License:Mozilla Public License
/** {@inheritDoc} */ public void updateDevice(String ipAddress, String managedNetwork, ZDeviceCore device) { ZDeviceCore dbDevice = getDevice(ipAddress, managedNetwork); if (dbDevice == null) { return;/*w ww .j a v a 2 s. c o m*/ } if (DeviceProviderActivator.getAdapterService().getAdapterMetadata(device.getAdapterId()) != null) { if (!dbDevice.getAdapterId().equals(device.getAdapterId())) { dbDevice.setAdapterId(device.getAdapterId()); deviceNotifier.notifyDeviceObservers(dbDevice, DeviceNotification.CHANGE_DEVICE_TYPE); } } // When setting the host name, we should accept any host name that is given. There are situations // where the hostname retrieved by DNS lookup gives us a string that does not validate. dbDevice.setHostname(device.getHostname()); //if (NetworkAddressElf.isValidHostname(device.getHostname())) //{ // dbDevice.setHostname(device.getHostname()); //} if (NetworkAddressElf.isValidAddress(device.getIpAddress())) { dbDevice.setIpAddress(NetworkAddressElf.toDatabaseString(device.getIpAddress())); } if (DeviceProviderActivator.getNetworksProvider().getManagedNetwork(device.getManagedNetwork()) != null) { dbDevice.setManagedNetwork(device.getManagedNetwork()); } SessionFactory sessionFactory = DeviceProviderActivator.getSessionFactory(); Session session = sessionFactory.getCurrentSession(); session.merge(dbDevice); }
From source file:org.yawlfoundation.yawl.util.HibernateEngine.java
License:Open Source License
private void updateOrMerge(Session session, Object obj) { try {/*from w ww .j av a2 s .c o m*/ session.saveOrUpdate(obj); } catch (Exception e) { session.merge(obj); } }
From source file:podd.dataaccess.hibernate.AbstractHibernateDAOImpl.java
License:Open Source License
@Override public void reattach(T entity) { if (entity != null) { Session session = getSession(); try {//from w ww.j av a2 s .c om if (PoddObject.class.isAssignableFrom(entity.getClass())) { PoddObject po = (PoddObject) entity; Long id = po.getId(); if (id != null) { try { session.buildLockRequest(LockOptions.NONE).lock(entity); } catch (NonUniqueObjectException e) { LOGGER.info("Merging entity instead of locking"); session.merge(entity); } catch (HibernateException e) { // Catch the following error // org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions LOGGER.info("Merging entity instead of locking"); session.merge(entity); } catch (HibernateSystemException e) { LOGGER.info("Merging entity instead of locking"); session.merge(entity); } } } } catch (HibernateException e) { LOGGER.warn("Found exception", e); } finally { releaseSession(session); } } }
From source file:py.una.pol.karaku.replication.client.ReplicationHandler.java
License:Open Source License
/** * @param entity/*from w w w. j a v a 2s .c o m*/ */ private void merge(ReplicationInfo ri, Shareable entity) { notNull(entity, "Cant merge a null entity"); Session s = sessionFactory.getCurrentSession(); Long id = getPersistedIdByUri(s, ri, entity.getUri()); if (id == null) { s.persist(entity); } else { BaseEntity toPersist = (BaseEntity) entity; toPersist.setId(id); s.merge(toPersist); } s.flush(); }