Skip to content

Support @ManyToOne inside @Embeddable for query predicates and joins#3816

Merged
rbygrave merged 8 commits into
masterfrom
embeddable_expansion
Jul 1, 2026
Merged

Support @ManyToOne inside @Embeddable for query predicates and joins#3816
rbygrave merged 8 commits into
masterfrom
embeddable_expansion

Conversation

@rob-bygrave

Copy link
Copy Markdown
Contributor

Fixes 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.

Closes #3710 (rebased, conflicts resolved, regressions fixed, tests added).

Changes

  • BeanPropertyAssocOne.buildElPropertyValue: correctly resolve @ManyToOne paths inside embedded — extract first segment, validate via embeddedPropsMap, delegate 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
  • Tests: 3 new test cases in TestEmbeddedManyToOne covering WHERE predicate through embedded FK column, through association property (requiring a JOIN), and combined with fetch

ghost81 and others added 8 commits July 1, 2026 21:34
 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
@rbygrave rbygrave self-assigned this Jul 1, 2026
@rbygrave rbygrave added this to the 18.2.0 milestone Jul 1, 2026
@rbygrave rbygrave merged commit 88d7b5e into master Jul 1, 2026
1 check passed
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.

3 participants