Skip to content

feat(core): fix duplicate issue with auditing#95

Merged
RVANDO12 merged 1 commit into
mainfrom
feat/audit/fix-duplicate
Jul 17, 2026
Merged

feat(core): fix duplicate issue with auditing#95
RVANDO12 merged 1 commit into
mainfrom
feat/audit/fix-duplicate

Conversation

@RVANDO12

@RVANDO12 RVANDO12 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

PR Description

Issue when batch update of relation between entity.

" Caused by: java.sql.BatchUpdateException: Batch entry 1 insert into idp_core.relation_target_entities_aud "
" ERROR: duplicate key value violates unique constraint "relation_target_entities_aud_pkey"

issue discover with peer testing :
When put an entity with exact same values, the process saved any way and log an audit modification => useless
When put an entity with relations but with a relation not in template definition => no error but relations is cleaned

Fixes

Database: Because hibernate envers does not flag modification on collections spring annoted with embeddable, we removed all unused _mod column on entity_template_relations_definitions_aud, entity_template_properties_definitions_aud,
entity_relations_aud, entity_properties_aud, relation_target_entities_aud

Code: Strip targetEntityUuid out of the equals() and hashCode() methods in RelationTargetJpaEntity.java so that the Java Set correctly prevents duplicates before they ever reach Hibernate Envers.

Fix message error when trying to update an entity with bad relation regarding template

Review

The reviewer must double-check these points:

  • The reviewer has tested the feature
  • The reviewer has reviewed the implementation of the feature
  • The documentation has been updated
  • The feature implementation respects the Technical Doc / ADR previously produced
  • The Pull Request title has a ! after the type/scope to identify the breaking
    change in the release note and ensure we will release a major version.

How to test

Update a huge information about entity to cause the issue and check is not appears

@github-code-quality

github-code-quality Bot commented Jul 13, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: Java

Java / code-coverage/jacoco

The overall coverage in the branch is 90%. The coverage in the branch is 89%.

Show a code coverage summary of the most impacted files.
File 5059903 b6855e5 +/-
com/decathlon/i...ity/Entity.java 100% 100% 0%
com/decathlon/i...y/Relation.java 100% 100% 0%
com/decathlon/i...tJpaEntity.java 75% 75% 0%
com/decathlon/i...ionService.java 81% 84% +3%
com/decathlon/i...ityService.java 94% 98% +4%
com/decathlon/i...enceMapper.java 73% 100% +27%

Updated July 17, 2026 13:55 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to address duplicate-key failures in Envers auditing during batch updates of entity relations by reducing unnecessary relation updates during merge operations, and by extending/strengthening test coverage around entity update payloads and persistence mapping.

Changes:

  • Added relation change detection in EntityPersistenceMapper.mergeRelations(...) to avoid updating unchanged relations (reducing unnecessary Envers audit writes).
  • Refactored EntityControllerTest request payloads to use JSON files under src/test/resources/... and added new update-with-relations scenarios.
  • Added a comprehensive EntityPersistenceMapperTest suite covering domain↔JPA mapping and merge behavior.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/com/decathlon/idp_core/infrastructure/adapters/persistence/mapper/EntityPersistenceMapper.java Adds relation change detection during merge to avoid unnecessary updates/audit writes.
src/test/java/com/decathlon/idp_core/infrastructure/adapters/api/controller/EntityControllerTest.java Switches multiple payloads to JSON fixtures; adds PUT relation-merge test scenarios.
src/test/java/com/decathlon/idp_core/infrastructure/adapters/persistence/mapper/EntityPersistenceMapperTest.java Adds extensive unit tests for persistence mapping and merge logic (including relation change detection).
src/test/resources/integration_test/json/entity/v1/putEntity_400_required_properties_missing.json New JSON fixture for PUT validation error scenario.
src/test/resources/integration_test/json/entity/v1/putEntity_400_property_type_mismatch.json New JSON fixture for PUT validation error scenario.
src/test/resources/integration_test/json/entity/v1/putEntity_400_property_rules_not_respected.json New JSON fixture for PUT validation error scenario.
src/test/resources/integration_test/json/entity/v1/putEntity_400_property_not_defined_and_relation_target_missing.json New JSON fixture for PUT combined validation error scenario.
src/test/resources/integration_test/json/entity/v1/putEntity_200_valid_update.json New JSON fixture for a valid PUT update.
src/test/resources/integration_test/json/entity/v1/putEntity_200_update_with_add_relation.json New JSON fixture for PUT update adding a relation.
src/test/resources/integration_test/json/entity/v1/putEntity_200_update_remove_all_relations.json New JSON fixture for PUT update removing all relations.
src/test/resources/integration_test/json/entity/v1/postEntity_400_required_properties_missing.json New JSON fixture for POST validation error scenario.
src/test/resources/integration_test/json/entity/v1/postEntity_400_relation_target_entity_does_not_exist.json New JSON fixture for POST validation error scenario.
src/test/resources/integration_test/json/entity/v1/postEntity_400_property_type_mismatch.json New JSON fixture for POST validation error scenario.
src/test/resources/integration_test/json/entity/v1/postEntity_400_property_rules_not_respected.json New JSON fixture for POST validation error scenario.
src/test/resources/integration_test/json/entity/v1/postEntity_400_property_not_defined_in_template.json New JSON fixture for POST validation error scenario.

@CLAassistant

CLAassistant commented Jul 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@RVANDO12
RVANDO12 force-pushed the feat/audit/fix-duplicate branch from 1558b75 to 073cb22 Compare July 16, 2026 13:24
Comment thread src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java Outdated
@RVANDO12
RVANDO12 force-pushed the feat/audit/fix-duplicate branch from c91fe3a to b153dce Compare July 17, 2026 10:07
Comment thread src/main/java/com/decathlon/idp_core/domain/service/entity/EntityService.java Outdated

@evebrnd evebrnd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested OK
Thanks for the fix !

@RVANDO12
RVANDO12 enabled auto-merge (squash) July 17, 2026 13:36
@RVANDO12
RVANDO12 disabled auto-merge July 17, 2026 13:39
@RVANDO12
RVANDO12 enabled auto-merge (squash) July 17, 2026 13:46
@RVANDO12
RVANDO12 force-pushed the feat/audit/fix-duplicate branch from 9d3e28e to b6855e5 Compare July 17, 2026 13:51
@sonarqubecloud

Copy link
Copy Markdown

@RVANDO12
RVANDO12 merged commit 977dbbc into main Jul 17, 2026
17 checks passed
@RVANDO12
RVANDO12 deleted the feat/audit/fix-duplicate branch July 17, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants