feat: Relationship JDBC insert/update [DHIS2-21378]#24093
Draft
enricocolasante wants to merge 6 commits into
Draft
feat: Relationship JDBC insert/update [DHIS2-21378]#24093enricocolasante wants to merge 6 commits into
enricocolasante wants to merge 6 commits into
Conversation
5ea4b99 to
1977d58
Compare
|
1977d58 to
146b6e8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Migrates the Relationship entity in the tracker importer from Hibernate (
EntityManager.persist)to raw JDBC, as part of the Hibernate→JDBC import migration (DHIS2-21378, Phase 6).
Relationships are written through a three-statement flush that breaks the non-deferrable circular
FK between
relationshipandrelationshipitem, and two cache-correctness fixes prevent the JDBCwrite path — which bypasses Hibernate's invalidation — from serving stale relationship reads or
silently disabling duplicate detection.
Changes
EntityWriteBatch.java): replacespersistAll(...)/em.persistwith three batched JDBC statements per flush — a multi-row INSERT intorelationship(withfrom/to_relationshipitemidleft NULL), a multi-row INSERT intorelationshipitemfor the from+to items, and anunnestUPDATE that backfills the from/to FKs.The three-step shape is required because the circular FK between the two tables is not deferrable
in the live schema. INSERT-only.
RelationshipPersister.java,AbstractTrackerPersister.java):sequenceName()now returnshibernate_sequence(wasnull) so relationship ids arepre-allocated, and
assignId(...)learns to assign the pre-allocated id toRelationship.Both
relationshipandrelationshipitemdraw ids from the shared globalhibernate_sequencefor now — this is temporary; dedicated sequences will be provisioned via a Flyway migration
(see Next Steps), since the shared counter is fragile (
RelationshipItem.idis a Javaintwhile the global sequence is bigint).
EntityWriteBatch.java): addstoObjectStyleJson(...)usingJsonBinaryType.MAPPERso thestylejsonbcolumn matches the HibernatejbObjectStyleUserType. Removes the now-unused
persistAllhelper.HibernateRelationshipStore.java): forces therelationship-key lookup off the query cache (
setCacheable(false)+QueryHints.CACHEABLE).JDBC writes bypass query-cache invalidation, so a cached empty result would otherwise linger
across imports and silently disable duplicate detection.
Relationship.hbm.xml,RelationshipItem.hbm.xml):removes
<cache usage="read-write"/>to avoid stale-cache reads of relationships/items writtenvia JDBC while the importer migration is in progress.
RelationshipImportTest.java,tracker/relationships_duplicate.json): addsshouldRejectDuplicateRelationships, asserting a second import of equivalent relationships isrejected with
E4018(2 ignored, 0 created). Cleans stray import-parameter keys out oftracker/relationships.json(they belong onTrackerImportParams, not the payload).Next Steps
Part of the DHIS2-21378 Hibernate→JDBC importer migration.
Done
store extraction, TEAV staging, top-level entity staging, named-query → JDBC).
To do
relationshipandrelationshipitem, replacing the shared globalhibernate_sequence. Required because the sharedcounter is fragile —
RelationshipItem.idis a Javaintwhile the global sequence is bigint —and a dedicated sequence makes the JDBC
allocateIdsallocation self-contained.EntityManager).EntityManagerfromAbstractTrackerPersister/EntityWriteBatch.