From dd4c29c90cdcaf89b7aa87912348e39943260af9 Mon Sep 17 00:00:00 2001 From: ds-lcapellino Date: Mon, 8 Jul 2024 12:47:57 +0200 Subject: [PATCH] bug: 1082 add retry in case of a duplicate key error --- .../repository/AssetAsPlannedRepositoryImpl.java | 1 - .../assets/infrastructure/base/irs/JobRepositoryImpl.java | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java index a6d16091b7..13e4b26659 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/asplanned/repository/AssetAsPlannedRepositoryImpl.java @@ -28,7 +28,6 @@ import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportNote; import org.eclipse.tractusx.traceability.assets.domain.base.model.ImportState; import org.eclipse.tractusx.traceability.assets.domain.base.model.Owner; -import org.eclipse.tractusx.traceability.assets.infrastructure.asbuilt.model.AssetAsBuiltEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.asplanned.model.AssetAsPlannedEntity; import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.AssetCallbackRepository; import org.eclipse.tractusx.traceability.assets.infrastructure.base.model.AssetBaseEntity; diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java index de3984ea79..e6a7eda7b8 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/assets/infrastructure/base/irs/JobRepositoryImpl.java @@ -35,6 +35,7 @@ import org.eclipse.tractusx.traceability.assets.infrastructure.base.irs.model.response.factory.IrsResponseAssetMapper; import org.eclipse.tractusx.traceability.common.properties.TraceabilityProperties; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.dao.DataIntegrityViolationException; import org.springframework.stereotype.Service; import java.util.List; @@ -108,7 +109,12 @@ public void handleJobFinishedCallback(String jobId, String state) { } void saveOrUpdateAssets(AssetCallbackRepository repository, AssetBase asset) { - repository.save(asset); + try { + repository.save(asset); + } catch (DataIntegrityViolationException ex) { + //retry save in case of ERROR: duplicate key value violates unique constraint "asset_pkey" + repository.save(asset); + } }