feat(core): fix duplicate issue with auditing#95
Conversation
Code Coverage OverviewLanguages: Java Java / code-coverage/jacocoThe overall coverage in the branch is 90%. The coverage in the branch is 89%. Show a code coverage summary of the most impacted files.
Updated |
There was a problem hiding this comment.
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
EntityControllerTestrequest payloads to use JSON files undersrc/test/resources/...and added new update-with-relations scenarios. - Added a comprehensive
EntityPersistenceMapperTestsuite 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. |
1558b75 to
073cb22
Compare
c91fe3a to
b153dce
Compare
evebrnd
left a comment
There was a problem hiding this comment.
Tested OK
Thanks for the fix !
9d3e28e to
b6855e5
Compare
|



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:
!after the type/scope to identify the breakingchange 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