Skip to content

FINERACT-2766: Tax Component - User should be able to edit a tax component - #6287

Open
rymghosn wants to merge 1 commit into
apache:developfrom
foodeveloper:port/CBS-86-tax-component-history-relationship-mapping
Open

FINERACT-2766: Tax Component - User should be able to edit a tax component#6287
rymghosn wants to merge 1 commit into
apache:developfrom
foodeveloper:port/CBS-86-tax-component-history-relationship-mapping

Conversation

@rymghosn

Copy link
Copy Markdown
Contributor

TaxComponent.taxComponentHistories was mapped as a unidirectional @onetomany with a @joincolumn(nullable = false) and no owning side (mappedBy)
declared on the child entity. This is a problematic pattern for a foreign-key-based one-to-many: since the parent's collection — not the child —
is left managing the relationship, adding a new TaxComponentHistory row to an already-persisted TaxComponent risks a flush-ordering issue against
the NOT NULL foreign key column. This is exactly what happens whenever a tax component's percentage or start date is edited
(TaxComponent.update() adds a new history entry to the collection).

This PR makes the relationship properly bidirectional:

  • Adds a @manytoone(optional = false) back-reference (taxComponent) on TaxComponentHistory, owning the foreign key via @joincolumn.
  • Changes TaxComponent.taxComponentHistories to @onetomany(mappedBy = "taxComponent", ...).
  • Updates TaxComponentHistory.createTaxComponentHistory(...) to accept and set the parent reference, and updates its single call site in
    TaxComponent.update().

No API/behavior changes — this is purely a persistence-mapping correctness fix, functionally equivalent for read paths but avoids the
flush-ordering hazard on write.

…onship bidirectional

The taxComponentHistories collection was mapped as a unidirectional
OneToMany with a NOT NULL JoinColumn and no owning side declared on
the child, which risks flush-ordering issues against the foreign key
when a new history row is added to an already-persisted TaxComponent
(exactly what happens when a tax component's percentage or start
date is edited). Add a ManyToOne back-reference on
TaxComponentHistory and let it own the foreign key via mappedBy.
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.

1 participant