ItEr42S13ImplantacionAplicacionItEr41S16: Fixing problem when saving an order.
Bypassing checking unique constraint when the hours group has null code in order to avoid exception
This commit is contained in:
parent
d9f0a0ee51
commit
737994f7db
2 changed files with 12 additions and 4 deletions
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
package org.navalplanner.business.orders.daos;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.hibernate.Criteria;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
import org.navalplanner.business.common.daos.GenericDAOHibernate;
|
||||
|
|
@ -65,9 +66,8 @@ public class HoursGroupDAO extends GenericDAOHibernate<HoursGroup, Long>
|
|||
|
||||
private HoursGroup findUniqueByCode(HoursGroup hoursGroup)
|
||||
throws InstanceNotFoundException {
|
||||
if ((hoursGroup == null) || (hoursGroup.getCode() == null)) {
|
||||
return null;
|
||||
}
|
||||
Validate.notNull(hoursGroup);
|
||||
Validate.notNull(hoursGroup.getCode());
|
||||
|
||||
Criteria c = getSession().createCriteria(HoursGroup.class);
|
||||
c.add(Restrictions.eq("code", hoursGroup.getCode()));
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hibernate.validator.AssertTrue;
|
||||
import org.hibernate.validator.NotEmpty;
|
||||
import org.hibernate.validator.NotNull;
|
||||
|
|
@ -43,6 +45,8 @@ import org.navalplanner.business.resources.entities.ResourceEnum;
|
|||
public class HoursGroup extends BaseEntity implements Cloneable,
|
||||
ICriterionRequirable {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(HoursGroup.class);
|
||||
|
||||
public static HoursGroup create(OrderLine parentOrderLine) {
|
||||
HoursGroup result = new HoursGroup(parentOrderLine);
|
||||
result.setNewObject(true);
|
||||
|
|
@ -281,8 +285,12 @@ public class HoursGroup extends BaseEntity implements Cloneable,
|
|||
|
||||
@AssertTrue(message = "code is already being used")
|
||||
public boolean checkConstraintUniqueCode() {
|
||||
if (code == null) {
|
||||
LOG.warn("Hours group code is null. "
|
||||
+ "Not checking unique code since it would fail");
|
||||
return true;
|
||||
}
|
||||
IHoursGroupDAO hoursGroupDAO = Registry.getHoursGroupDAO();
|
||||
|
||||
if (isNewObject()) {
|
||||
return !hoursGroupDAO.existsByCodeAnotherTransaction(this);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue