ItEr13S15ProbasModuloRecursosItEr12S10: Adds merge method to GenericDAO
This commit is contained in:
parent
ab8af23678
commit
cf12b09255
3 changed files with 18 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue