The GitHub Actions job "CI" on 
grails-core.git/fix/hibernate7-composite-fk-column-types-8.0.x has succeeded.
Run started by GitHub user borinquenkid (triggered by borinquenkid).

Head commit for run:
0b0be81a047af4126332c8b01b032794ec7219f1 / Walter Duque de Estrada 
<[email protected]>
fix: sort a composite foreign key once the identifier it references is bound

CompositeIdentifierToManyToOneBinder sorted a key against the referenced
composite identifier while binding the property. When the referenced entity
had not been bound yet, the columns kept their declared order, got sequential
type indexes and were marked sorted, so Hibernate's own ToOne.sortProperties()
skipped them too, and PropertyFromValueCreator created Hibernate's foreign key,
which pairs the columns by position. Whether a key came out right therefore
depended on the registration order of the entities, which an application does
not choose: PrbGrand, PrbLeaf, PrbMiddle left the leaf's key in declared order
while its values were bound in key order, and saving a leaf failed with a
referential integrity violation; a middle registered before its grand parent
crossed the alpha and zeta columns of every key referencing it.

The binder now aligns a key only once the referenced identifier is bound, down
to the identifiers its to-one parts reference. Otherwise it registers a
CompositeForeignKeySecondPass through InFlightMetadataCollector.addSecondPass,
the mechanism the binder already uses for collections, which Hibernate runs
before it compiles the foreign keys; this mirrors ToOne.sortProperties(), which
resolves the referenced identifier lazily from the second passes. The alignment
is idempotent and aligns the pending to-one parts of the referenced identifier
first, so a key referencing a middle whose own key is still pending sees the
middle's sorted columns; a key bound during the second passes is aligned at
once. PropertyFromValueCreator leaves the foreign key of a many-to-one to a
composite identifier to the composite binder, which pairs each column with the
identifier column it references; for a referenced entity registered first the
binder had already disabled Hibernate's key, so those keys are unchanged.

CompositeForeignKeyRegistrationOrderSpec boots the entities of
CompositeForeignKeyColumnTypesSpec in five registration orders and asserts the
KEY_SEQ pairs and a save and reload; four of them failed before this change.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

Report URL: https://github.com/apache/grails-core/actions/runs/37939803633

With regards,
GitHub Actions via GitBox

Reply via email to