Repository navigation
Hibernate 7: write the rows of lists and maps that share a join table - #16756
Conversation
|
CI run 40132431052 is green, with its tests run ( |
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. Lists and maps that share a table can be inserted, but two lists that also share the element column still load and delete each other's rows.
|
Resolved the row collision when collections share both foreign-key and element columns:
|
jamesfredley
left a comment
There was a problem hiding this comment.
The earlier comment is fixed. Each shared list is restricted by its own index column, clearing one keeps the other, and loading no longer selects the other list's rows. That thread is resolved. Not approving yet, only because the migration steps leave an existing table unable to take rows from the other list.
jamesfredley
left a comment
There was a problem hiding this comment.
Approving. The upgrade note now says to drop the primary key and make the owner-key and index columns nullable, which is what the binder does. That comment is resolved.
|
@borinquenkid Please update the upgrade skill in addition to the guide. |
jdaugherty
left a comment
There was a problem hiding this comment.
Reviewed the full diff against the stacked base at e635103. No new actionable findings in the supported shared-list and shared-map cases. The earlier row-isolation and migration comments are addressed.
Validation: ./gradlew :grails-data-hibernate7-core:test --console=plain --max-workers=4 passed with 4,311 tests, 4,292 successes, 0 failures, and 19 skipped. This run included three temporary review tests covering three lists sharing the owner and element columns during reorder/clear, HQL and criteria query isolation, and maps sharing those columns during replacement, removal, and clearing; all passed.
The PR tests also passed against H2, PostgreSQL, MySQL, MariaDB, and Oracle locally. Db2 runtime coverage was skipped on ARM; SQL Server and IBM i/z/OS behavior was checked through the existing dialect/DDL coverage rather than live databases. Mixed set/list sharing remains outside this verification.
The failing CI job reports ForwardingSpec in grails-test-examples-app1, which does not appear related to this diff.
The only ask I still have is to update the Grails Upgrade skill.
|
@jdaugherty Updated in commit 7ca0fd6: added the shared join table behavior and schema migration instructions to the Grails 8 upgrade skill (). |
This comment has been minimized.
This comment has been minimized.
7ca0fd6 to
a62c6df
Compare
…he Groovy sources 8.0.x gained the QueryParameters/QuerySettings split of HqlQueryContext (#16800) and the shared join table list fix (#16756) after this branch was cut from 10.0.x. Their Java sources were converted here by hand: QueryParameters and QuerySettings are new Groovy records, HqlQueryContext, HqlQueryMethods, SelectHqlQuery and MutationHqlQuery follow the 8.0.x change, and the Java SharedJoinTable classes and the specs and docs of those commits apply as they are. A merge of 8.0.x into 10.0.x would otherwise conflict on the deleted Java files; resolve those by keeping the Groovy sources. The ByteBuddyGroovyProxyFactorySpec feature of the proxy-walk commit (#16721) is left out: it needs the grails-datastore-core change of that commit. Claude-Session: https://claude.ai/code/session_01Dmki4SQGwRSj8pRJ5KCWyX
Fixes #16700. Stacked on #16750 (it builds on the shared join table uniqueness of #16701 and the Db2 rules of #16750); retarget to
8.0.xonce those merge.Problem
Two unidirectional
hasManylists (or maps) to the same class that share one join table could not be saved:Hibernate keys the join table of a list or a map with a primary key over its key and index columns (
IndexedCollection.createPrimaryKey). On a shared table the next collection replaces it with its own, and it makes those columnsNOT NULL, while a row of one list leaves the other list's columns null.Change
SharedJoinTableUniqueKeyBinder, for each list or map of a shared table: makes its key and index columns nullable, drops that primary key, and gives it a uniqueness of its own over its key and index columns throughSharedJoinTableUniqueness, the same per-database rules sets get:create unique where not null indexper listA position or a map key is taken once; an element may repeat, as a list allows. On Oracle and Db2 LUW
SharedJoinTableUniquenessnow creates the key when there is none to widen, since a list has no implicit unique key (a set always has one, so sets are unchanged).Tests
SharedJoinTableListHibernate7Spec(new): both shapes keep their lists in order; removing from one list keeps the other and the order of the rest; an element may repeat and clearing one list keeps the other; two maps keep their entries. A container feature writes and reads both shapes on H2, PostgreSQL, MySQL, MariaDB, Oracle and Db2 (CI, amd64), and checks that a second row at a taken position is rejected; with the uniqueness removed every database accepts it.SharedJoinTableUniqueKeyBinderSpec: the DDL of two shared lists on H2, Oracle, Db2 LUW, IBM i and SQL Server (55/0).grails-data-hibernate7-coresuite locally: 4293 tests, 0 failures (the sharedDatabaseContainersof Hibernate 7: support Db2 in unique key null handling, regular expressions and native SQL reading #16750 makes the Oracle rows pass locally too).Not covered: a set that shares a join table with a list.
Docs
The shared join table note of the 8.0.x upgrade guide, with the migration a schema created by an earlier Grails 8 release needs (drop the primary key, make the index columns nullable;
dbCreate: updatechanges neither), and the one-to-many chapter.https://claude.ai/code/session_01MDHn7fC3hsGJ27vFHD2o1p