Skip to content

HHH-20827 - Fix lazy loading for abstract @ConcreteProxy entities - #13490

Merged
beikov merged 1 commit into
hibernate:8.0from
yashagraawal:HHH-20827
Sep 22, 2026
Merged

beikov merged 1 commit into
hibernate:8.0from
yashagraawal:HHH-20827

Conversation

@yashagraawal

@yashagraawal yashagraawal commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary:
Fixes lazy loading for @manytoone associations targeting abstract @ConcreteProxy entities when bytecode enhancement is disabled.

Problem:

  • Lazy @manytoone references to abstract entities annotated with @ConcreteProxy were being eagerly loaded
  • Hibernate was not creating proxy factories for abstract @ConcreteProxy entities, assuming proxies weren't needed for abstract classes
  • On JDK 25, attempts to create proxies for sealed classes caused IncompatibleClassChangeError

Solution:

  1. Create ProxyFactory for abstract @ConcreteProxy entities - Enable proxy creation when the entity is abstract, uses @ConcreteProxy, is not sealed, and lazy loading is enabled
  2. Exclude sealed classes from proxy creation - Add sealed class checks to prevent ByteBuddy errors on JDK 25
  3. Select discriminator for @ConcreteProxy entities - Ensure discriminator columns are selected for @ConcreteProxy entities with subclasses so Hibernate can resolve the concrete entity type

Testing:

  • All 23 ConcreteProxy tests pass
  • ConcreteProxyWithSealedClassesTest passes (3/3) - JDK 25 compatibility
  • New test: testAbstractSingleTable() validates abstract @ConcreteProxy lazy loading
  • Tested on JDK 17, 21, and 25

Files Changed:

  • EntityRepresentationStrategyPojoStandard.java - Proxy factory creation for abstract @ConcreteProxy + sealed class exclusion
  • EntityFetchSelectImpl.java - Discriminator selection for @ConcreteProxy with subclasses
  • ConcreteProxyTest.java - Test coverage for abstract @ConcreteProxy entities

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.



Please make sure that the following tasks are completed:
Tasks specific to HHH-20827 (Bug):

  • Add test reproducing the bug
  • Add entries as relevant to migration-guide.adoc OR check there are no breaking changes

https://hibernate.atlassian.net/browse/HHH-20827

@hibernate-github-bot hibernate-github-bot Bot added the 8.0 Label for pull requests targeting [8.0] branch. label Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026

Copy link
Copy Markdown

Documentation Preview

This preview has been removed following the closure of this PR.

@yashagraawal

Copy link
Copy Markdown
Contributor Author

Hi @beikov, I see a GH action (GraalVM 25 - autonomous-transaction-processing-serverless-19c) failing with 504, could you please confirm and re-trigger it ? Thanks!

@beikov
beikov merged commit edff407 into hibernate:8.0 Sep 22, 2026
49 of 51 checks passed
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.0 Label for pull requests targeting [8.0] branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants