Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.hibernate.bytecode.enhance.spi.EnhancementException: Enhancement of [org.acme.domain.MyEntity] failed #44863

Open
KaiSuchomel opened this issue Dec 2, 2024 · 2 comments
Labels
area/hibernate-orm Hibernate ORM kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.

Comments

@KaiSuchomel
Copy link
Contributor

KaiSuchomel commented Dec 2, 2024

Describe the bug

Exception occurs during Build:
org.hibernate.bytecode.enhance.spi.EnhancementException: Enhancement of [org.acme.domain.MyEntity] failed because no field named [modelType] could be found for property accessor method [getModelType]. To fix this, make sure all property accessor methods have a matching field.

Expected behavior

The Build should succeed.

Actual behavior

When building the project:
ERROR] Caused by: java.util.concurrent.ExecutionException: org.hibernate.bytecode.enhance.spi.EnhancementException: Enhancement of [org.acme.domain.MyEntity] failed because no field named [modelType] could be found for property accessor method [getModelType]. To fix this, make sure all property accessor methods have a matching field.

How to Reproduce?

Reproducer: https://github.com/KaiSuchomel/quarkus-test/tree/hibernate
Just build the project with maven.
Simple Entity:

@Entity
public class MyEntity {

    @Id
    private UUID id;

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public void getXXX() {
    }

    @PrePersist
    public void setId(){
        id = UUID.randomUUID();
    }
    
    public String getModelType() {
        return "MyEntity";
    }
}

After changing the PrePersist setter to a seperate name the build is working:

@Entity
public class MyEntity {

    @Id
    private UUID id;

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public void getXXX() {
    }

    @PrePersist
    public void prePersistSetId(){
        id = UUID.randomUUID();
    }
    
    public String getModelType() {
        return "MyEntity";
    }
}

Output of uname -a or ver

Darwin Mac-C6VD4H4XT3 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:00:32 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6030 arm64

Output of java -version

openjdk version "21.0.5" 2024-10-15 OpenJDK Runtime Environment Homebrew (build 21.0.5) OpenJDK 64-Bit Server VM Homebrew (build 21.0.5, mixed mode, sharing)

Quarkus version or git rev

3.17.2 --> hibernate-core 6.6.3

Build tool (ie. output of mvnw --version or gradlew --version)

Maven home: /opt/homebrew/Cellar/maven/3.9.9/libexec Java version: 21.0.5, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk@21/21.0.5/libexec/openjdk.jdk/Contents/Home Default locale: de_DE, platform encoding: UTF-8 OS name: "mac os x", version: "15.1.1", arch: "aarch64", family: "mac"

Additional information

@yrodiere Can you please check. Thx.
See: hibernate/hibernate-orm@b5221e2#diff-5f775bce3db8bc5527104f2eba37fef522276d3bed00a3276545528ab233c380R16

@KaiSuchomel KaiSuchomel added the kind/bug Something isn't working label Dec 2, 2024
@quarkus-bot quarkus-bot bot added the area/hibernate-orm Hibernate ORM label Dec 2, 2024
Copy link

quarkus-bot bot commented Dec 2, 2024

/cc @gsmet (hibernate-orm), @yrodiere (hibernate-orm)

@mbladel
Copy link
Contributor

mbladel commented Dec 2, 2024

Hello @KaiSuchomel, thank you for reporting the issue and providing a simple mapping which reproduces your problem.

The error you're facing is caused by a recent change in Hibernate's bytecode-enhancement logic: https://hibernate.atlassian.net/browse/HHH-16572. The new check is needed because support for bytecode enhanced entities with AccessType.PROPERTY (using getter/setter methods instead of fields) does not function properly unless the field names exactly match the method names - in Quarkus this can be especially problematic since enhancement is done at build-time and we expect all entities to be enhanced at runtime.

Using setX, where X is a persistent property name, as the method name in your entity classes is generally not a good idea, especially when using bytecode-enhancement, as the method could be mistaken as a setter for that field. So the "workaround" you found is more than valid and I would suggest keeping that as-is.

Regardless, I believe the check should work in this case since:

  1. The entity is using AccessType.FIELD, since the @Id annotation is placed on the id field;
  2. The pre-persist method setId corresponds to an actually existing field
  3. The pre-persist method setId has no arguments, so it cannot be an actual setter

We should open an issue on Hibernate ORM's Jira to keep track of this and possibly improve the check.

Edit: created https://hibernate.atlassian.net/browse/HHH-18904

@gsmet gsmet added kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus. and removed kind/bug Something isn't working labels Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/hibernate-orm Hibernate ORM kind/bug-thirdparty Bugs that are caused by third-party components and not causing a major dysfunction of core Quarkus.
Projects
None yet
Development

No branches or pull requests

3 participants