Support @ManyToOne inside @Embeddable for query predicates and joins#3816
Merged
Conversation
Fix path resolution for @manytoone associations nested inside @embeddable classes. Previously, a query like .where().eq("address.country.name", "NZ") on an entity with an @Embedded EAddr (containing @manytoone Country country) would throw PersistenceException: Embedded Property country.name not found. Changes: - BeanPropertyAssocOne.buildElPropertyValue: correctly resolve @manytoone paths inside embedded by extracting first segment, validating via embeddedPropsMap, then delegating deeper traversal to the overridden property; restore embedded flag on ElPropertyChain for scalar leaves - BeanPropertyAssoc.targetDescriptor(): lazy-init fix for override copies created by BeanEmbeddedMetaFactory (initialise() is not called on them) - BeanDescriptor.extraJoin(): restore !assocProp.isEmbedded() guard to prevent null-table ExtraJoin for composite keys and other embeddables - ElPropertyChainBuilder/ElPropertyChain: restore embedded field and prefix computation so alias resolution works correctly for paths through embedded (e.g. outer.datePeriod.date1 → prefix "outer" not "outer.datePeriod") - SqlTreeBuilder.buildExtraJoins: remove erroneous removeAll on orderByIncludes that broke Formula2 placeholder resolution and distinct on aggregation queries with many-side order-by joins - SqlTreeAlias.addJoin: fix indentation - Tests: add three test cases to TestEmbeddedManyToOne covering WHERE predicate through embedded FK column, through association property (requiring a JOIN), and combined with fetch
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.
Fixes path resolution for
@ManyToOneassociations nested inside@Embeddableclasses.Previously, a query like
.where().eq("address.country.name", "NZ")on an entity with an@Embedded EAddr(containing@ManyToOne Country country) would throwPersistenceException: Embedded Property country.name not found.Closes #3710 (rebased, conflicts resolved, regressions fixed, tests added).
Changes
BeanPropertyAssocOne.buildElPropertyValue: correctly resolve@ManyToOnepaths inside embedded — extract first segment, validate viaembeddedPropsMap, delegate deeper traversal to the overridden property; restoreembeddedflag onElPropertyChainfor scalar leavesBeanPropertyAssoc.targetDescriptor(): lazy-init fix for override copies created byBeanEmbeddedMetaFactory(initialise()is not called on them)BeanDescriptor.extraJoin(): restore!assocProp.isEmbedded()guard to prevent null-tableExtraJoinfor composite keys and other embeddablesElPropertyChainBuilder/ElPropertyChain: restoreembeddedfield and prefix computation so alias resolution works correctly for paths through embedded (e.g.outer.datePeriod.date1→ prefix"outer"not"outer.datePeriod")SqlTreeBuilder.buildExtraJoins: remove erroneousremoveAllonorderByIncludesthat broke Formula2 placeholder resolution anddistincton aggregation queries with many-side order-by joinsTestEmbeddedManyToOnecovering WHERE predicate through embedded FK column, through association property (requiring a JOIN), and combined with fetch