diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java index 77e3b36a745..88cba2f4a45 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionDeliverySubscriber.java @@ -21,6 +21,7 @@ package ca.uhn.fhir.jpa.subscription; */ import ca.uhn.fhir.jpa.dao.IFhirResourceDao; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Subscription; @@ -62,7 +63,15 @@ public abstract class BaseSubscriptionDeliverySubscriber extends BaseSubscriptio IIdType payloadId = msg.getPayloadId(getContext()); Class type = getContext().getResourceDefinition(payloadId.getResourceType()).getImplementingClass(); IFhirResourceDao dao = getSubscriptionDao().getDao(type); - IBaseResource loadedPayload = dao.read(payloadId); + IBaseResource loadedPayload; + try { + loadedPayload = dao.read(payloadId); + } catch (ResourceNotFoundException e) { + // This can happen if a last minute failure happens when saving a resource, + // eg a constraint causes the transaction to roll back on commit + ourLog.warn("Unable to find resource {} - Aborting delivery", payloadId.getValue()); + return; + } msg.setPayload(getContext(), loadedPayload); } diff --git a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt index 1e8c7df6044..962e59816c6 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt +++ b/hapi-fhir-jpaserver-uhnfhirtest/derby_maintenance.txt @@ -92,6 +92,18 @@ delete from hfj_spidx_uri where res_id in (select res_id from hfj_resource); delete from hfj_res_tag where res_id in (select res_id from hfj_resource); delete from hfj_search_result where resource_pid in (select res_id from hfj_resource); delete from hfj_res_param_present where res_id in (select res_id from hfj_resource); +delete from hfj_idx_cmp_string_uniq where res_id in (select res_id from hfj_resource); +delete from hfj_subscription_stats where res_id in (select res_id from hfj_resource); delete from hfj_resource where res_id in (select res_id from hfj_resource); +# Correct Version issues +update hfj_resource +set res_ver = res_ver + 1 +where res_id in ( + select distinct res.res_id from hfj_resource res + inner join hfj_res_ver rv on (rv.res_id = res.res_id) + where ((res.res_ver + 1) = (rv.res_ver)) +) + +