Bytecode enhancement leads to broken constructor for a generic embedded field in a MappedSuperclass

Description

Affects ORM 6.3 (current main) and 6.2.5, at least. I think 6.2.4 and below were a bit less affected, because they didn’t detect composite fields correctly (see HHH-16774), so one might not have noticed when using e.g. @EmbeddedId, but the bug was already there when using @Embedded.

With the following model, one will get this exception when calling MyEntity’s constructor:

Model:

The bug also affects @EmbeddedId, but that seems irrelevant.

I will submit a PR with a reproducer ASAP.

Activity

Show:

Yoann Rodière June 21, 2023 at 10:44 AM

Workaround for those affected: change the visibility of the field annotated with @Embedded/ @EmbeddedId to protected (or the default package-private visibility if the mapped superclass and subclass are in the same package). This will cause Hibernate ORM to generate different bytecode unaffected by this bug.

Yoann Rodière June 21, 2023 at 10:38 AM

Note this is affecting Quarkus' test suite:

Yoann Rodière June 21, 2023 at 10:37 AM

Reproducer:

As far as I can see, the problem is in https://github.com/hibernate/hibernate-orm/blob/5a63d8758a79d8bbcd923ace0bd111623659a6e8/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/InlineDirtyCheckingHandler.java#L88-L90: GetterMapping doesn't seem to work correctly when the getter is defined in the superclass with a more abstract type.

Fixed

Details

Assignee

Reporter

Components

Sprint

Fix versions

Affects versions

Priority

Created June 21, 2023 at 10:34 AM
Updated August 4, 2023 at 4:26 PM
Resolved June 26, 2023 at 4:10 PM