ItEr13S15ProbasModuloRecursosItEr12S10: Adds merge method to GenericDAO

This commit is contained in:
Diego Pino Garcia 2009-06-24 14:00:28 +02:00 committed by Javier Moran Rua
parent ab8af23678
commit cf12b09255
3 changed files with 18 additions and 0 deletions

View file

@ -27,6 +27,16 @@ public interface IGenericDao <E, PK extends Serializable>{
*/
public void save(E entity);
/**
* Merges an entity, useful when saving an entity and a different object
*
* Unlike save, it does not launch an Exception if there is already a
* persistent instance with the same identifier in the session
*
* @param entity
*/
public E merge(E entity);
/**
* It checks if the version of the instance passed as a parameter is equal
* to the one in the database. The instance must have methods conforming to

View file

@ -77,6 +77,10 @@ public class GenericDaoHibernate<E, PK extends Serializable> implements
}
public E merge(E entity) {
return entityClass.cast(getSession().merge(entity));
}
public void checkVersion(E entity) {
/* Get id and version from entity. */

View file

@ -62,6 +62,10 @@ public class GenericDaoHibernateTemplate<E, PK extends Serializable> implements
hibernateTemplate.saveOrUpdate(entity);
}
public E merge(E entity) {
return entityClass.cast(hibernateTemplate.merge(entity));
}
public void checkVersion(E entity) {
/* Get id and version from entity. */