From 47cd02e0a929147c12c37a40f3328298b4814a63 Mon Sep 17 00:00:00 2001 From: Anthony Britton <105213050+anthony-britton-moj@users.noreply.github.com> Date: Tue, 24 Oct 2023 16:59:33 +0100 Subject: [PATCH] PI-1586 added explicit save to old before new for constraint (#2444) --- .../justice/digital/hmpps/services/PrisonManagerService.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PrisonManagerService.kt b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PrisonManagerService.kt index 429757aed3..83ff5e204a 100644 --- a/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PrisonManagerService.kt +++ b/projects/manage-pom-cases-and-delius/src/main/kotlin/uk/gov/justice/digital/hmpps/services/PrisonManagerService.kt @@ -35,7 +35,10 @@ class PrisonManagerService( val staff = getStaff(probationArea, team, allocation.manager, allocationDate) val currentPom = prisonManagerRepository.findActiveManagerAtDate(personId, allocationDate) val newPom = currentPom.changeTo(personId, allocationDate, probationArea, team, staff) - prisonManagerRepository.save(newPom) + newPom?.let { new -> + currentPom?.let { old -> prisonManagerRepository.saveAndFlush(old) } + prisonManagerRepository.save(new) + } } private fun getStaff( @@ -84,6 +87,6 @@ class PrisonManagerService( } newPom } else { - this + null } }