From fd7b4648fa54405e1cc5cb1f129aaa029f2b59ce Mon Sep 17 00:00:00 2001 From: Javier Moran Rua Date: Mon, 27 Jul 2009 22:24:58 +0200 Subject: [PATCH] ItEr18S14CUAsignacionRecursosEspecificosAPlanificacion: Corrected load of criterions to avoid LazyInitializationException and duplicated objects in the session. --- .../web/planner/ResourceAllocationModel.java | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/ResourceAllocationModel.java index 06a7a8d07..c683507d9 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/ResourceAllocationModel.java @@ -5,6 +5,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.hibernate.LockMode; +import org.hibernate.SessionFactory; import org.navalplanner.business.common.exceptions.InstanceNotFoundException; import org.navalplanner.business.orders.daos.IHoursGroupDao; import org.navalplanner.business.orders.entities.HoursGroup; @@ -26,7 +28,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; /** - * Model for UI operations related to {@link Task}. + * Model for UI operations related to {@link Task} * * @author Manuel Rego Casasnovas */ @@ -40,6 +42,9 @@ public class ResourceAllocationModel implements IResourceAllocationModel { @Autowired private IWorkerDao workerDAO; + @Autowired + private SessionFactory sessionFactory; + @Autowired private IHoursGroupDao hoursGroupDAO; @@ -139,28 +144,38 @@ public class ResourceAllocationModel implements IResourceAllocationModel { } @Override + @Transactional(readOnly=true) public Worker getWorker() { if (resourceAllocation == null) { return null; } - return ((SpecificResourceAllocation) resourceAllocation).getWorker(); + Worker worker = ((SpecificResourceAllocation) resourceAllocation) + .getWorker(); + if(worker == null) { + return null; + } + try { + return workerDAO.find(worker.getId()); + } catch (InstanceNotFoundException e) { + throw new RuntimeException(e); + } } @Override + @Transactional(readOnly = true) public boolean workerSatisfiesCriterions() { + + for (Criterion criterion : getCriterions()) { + sessionFactory.getCurrentSession().lock(criterion, LockMode.NONE); + } + Worker worker = getWorker(); + if (worker == null) { return true; } - - List criterions = new ArrayList(getCriterions()); - if (criterions.isEmpty()) { - return true; - } - - ICriterion compositedCriterion = CriterionCompounder.buildAnd(criterions) - .getResult(); + ICriterion compositedCriterion = CriterionCompounder.buildAnd( + new ArrayList(getCriterions())).getResult(); return compositedCriterion.isSatisfiedBy(worker); } - } \ No newline at end of file