Repository navigation
fix(hibernate5): join an abstract root that follows a joined subclass, and place a joined subclass in its schema - #16904
borinquenkid wants to merge 10 commits into
Conversation
…ed under an abstract base class An abstract base class with the default strategy made a subclass that sets tablePerHierarchy false a single-table subclass, while that subclass's own children were joined, so loading them asked for a discriminator column the joined table does not have. The abstract base class now follows the subclass and the hierarchy is joined. Fixes #14423 Claude-Session: https://claude.ai/code/session_01Dmki4SQGwRSj8pRJ5KCWyX
…og it declares The table of a joined subclass always took the default schema, so a subclass that declares its own schema was created, and queried, in the wrong one. It now uses the schema and catalog from its table mapping, as the root class and the table-per-concrete class subclass already do. Fixes #14427 Claude-Session: https://claude.ai/code/session_01Dmki4SQGwRSj8pRJ5KCWyX
…s on the datasource being built An abstract base class that says nothing about its strategy is joined when a subclass sets tablePerHierarchy false. The binder wrote that into the mapping of the base class, which every datasource shares, so a datasource built later saw a joined base class it never inferred, and the unconfigured subclasses of an unconfigured child stayed single-table under a base class that had lost its discriminator. The inference now belongs to the binder, which builds one datasource, and every read of the strategy goes through it: the whole hierarchy under an inferred base class is joined on that datasource only. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…eps it A base class that says tablePerHierarchy true, or tablePerSubclass false, was inferred as joined when a subclass sets tablePerHierarchy false, and its own rows stopped being returned. Mapping now records whether the strategy was declared, and only a base class that did not declare one follows its subclass. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…r the inherited schema and catalog The inferred joined hierarchy is found with the root entity of the mapping model and isAssignableFrom, not by walking the Java classes, so an abstract root that extends a class that is not a domain class is joined. The declared-strategy flag on Mapping is private with a getter. Specs: a plain parent class, a schema that only the base class declares, and the catalog of a joined subclass. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
…-memory database treats a declared catalog Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
… and add the upgrade note The catalog of a joined subclass is observed on a real MariaDB (Testcontainers), where a catalog is the database a table is created in; the spec fails without the catalog branch of the binder. The 8.1 upgrade guide describes the joined hierarchy under an abstract root and the schema and catalog of a joined subclass. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
jamesfredley
left a comment
There was a problem hiding this comment.
Not approving. A formula property on a joined subclass is stored as a column, so the computed value is lost.
| Mapping m = getMapping(parent.getMappedClass()); | ||
| Subclass subClass; | ||
| boolean tablePerSubclass = m != null && !m.getTablePerHierarchy() && !m.isTablePerConcreteClass(); | ||
| boolean tablePerSubclass = m != null && !isTablePerHierarchy(parent.getMappedClass(), m) && !m.isTablePerConcreteClass(); |
There was a problem hiding this comment.
An abstract root with no declared strategy, and a subclass that sets tablePerHierarchy false and maps doubled as formula amount * 2. Saving amount 7 stores doubled as 0. The formula is never marked derived, so it is bound as a column. Mark derived properties before choosing the subclass strategy.
…derived, not bound as a column The properties with a formula were marked derived only for the root of a hierarchy and for the subclasses of a single table. A joined subclass, and a union one, bound a formula property as a column of its own table, so saving stored nothing for it and reading returned null instead of the formula. The properties are marked before the strategy of the subclass is chosen. Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
@jamesfredley Reproduced, and fixed in the new commit. The properties with a formula were marked derived for the root of a hierarchy and for the subclasses of a single table, and not for the others, so a joined subclass bound them as columns. They are marked before the strategy of the subclass is chosen now. A union subclass ( The Hibernate 5 module (1,181 tests) and If you find another shape that does not reproduce first time, a failing spec on a throwaway branch, or the few lines you ran, would help me a lot. |
jamesfredley
left a comment
There was a problem hiding this comment.
Requested changes. A formula on an enum property of a joined subclass is still stored as a column.
| // column of its own table, which holds no value for it. | ||
| Mapping subMapping = getMapping(sub); | ||
| if (subMapping != null) { | ||
| configureDerivedProperties(sub, subMapping); |
There was a problem hiding this comment.
A joined subclass has an enum property whose value comes from a formula. This marks other formula properties as derived. The enum still gets a column, because the enum path does not check that. Use the formula.
…mula and has no column Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
|
Pushed 33a8502. You are right: this pull request marks every formula property of a joined or union subclass as derived ( The test: |
Splits the table-layout changes out of #16845, which fits a patch release only without them. These two change the tables of an application that maps a joined hierarchy:
tablePerHierarchy false, so the hierarchy is joined and not half single-table. The root is found with the root entity of the mapping model, so an abstract root that extends a class that is not a domain class is joined too.tablemapping. The mapping of the base class is inherited, so atable schema:declared only on the base class now also places the subclass table.Upgrade note. A hierarchy with an abstract root and a child that sets
tablePerHierarchy falsenow has a table for the child and noclasscolumn on the root; an application with a managed schema has to add the table and move its rows. To keep the old layout, declaretablePerHierarchy trueon the root: a root that declares its strategy keeps it. A joined subclass whose base class declarestable schema:now lives in that schema. The 8.1 upgrade guide has the entry (6).The catalog of a joined subclass is tested on a real MariaDB (Testcontainers), where a catalog is the database a table is created in; the spec fails without the catalog branch of the binder.
Fixes #14423
Fixes #14427
Continues #16845.
https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL