diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/IGenericDao.java b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/IGenericDao.java index 913b69ebb..3bb29be8c 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/IGenericDao.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/IGenericDao.java @@ -46,10 +46,10 @@ public interface IGenericDao { *
* If the check is not passed, * org.springframework.dao.OptimisticLockingFailureException - * is thrown. If the key of the entity is null or the entity - * does not exist in database, the check is considered to be successful. - * This lets client code to treat creation and modification of instances in - * a unified way. + * is thrown. If the key or the version of the entity is null, + * or the entity does not exist in database, the check is considered to be + * successful. This lets client code to treat creation and modification of + * instances in a unified way. */ public void checkVersion(E entity); diff --git a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/impl/GenericDaoHibernate.java b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/impl/GenericDaoHibernate.java index f227032d2..8afb7fc94 100644 --- a/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/impl/GenericDaoHibernate.java +++ b/navalplanner-business/src/main/java/org/navalplanner/business/common/daos/impl/GenericDaoHibernate.java @@ -85,7 +85,7 @@ public class GenericDaoHibernate implements /* Get id and version from entity. */ Serializable id; - long versionValueInMemory; + Long versionValueInMemory; try { @@ -99,6 +99,10 @@ public class GenericDaoHibernate implements Method getVersionMethod = entityClass.getMethod("getVersion"); versionValueInMemory = (Long) getVersionMethod.invoke(entity); + if (versionValueInMemory == null) { + return; + } + } catch (Exception e) { throw new RuntimeException(e); } @@ -116,7 +120,7 @@ public class GenericDaoHibernate implements return; } - if (versionValueInMemory != versionValueInDB) { + if (!versionValueInMemory.equals(versionValueInDB)) { throw new StaleObjectStateException(entityClass.getName(), id); }