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

quarkus-hibernate-orm - lazy loading of parameterized attributes from MappedSuperclass with getter does not work. #40719

Closed
mapuci opened this issue May 19, 2024 · 5 comments
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working

Comments

@mapuci
Copy link

mapuci commented May 19, 2024

Describe the bug

Reproducer: https://github.com/mapuci/hibernate-parameterized-mappedsuperclass

  • contains issue reproducer with quarkus
  • contains working example with same entities in wildfly

I believe reading the simple reproducer code offers the best explanation.

If you have read the code and README, stop reading.

We have entity and its abstract parameterized MappedSuperclass:

@MappedSuperclass
public abstract class AbsOne<TWO extends AbsTwo<?, ?>> {
    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "two_id")
    private TWO two;
//... getters, setters... are ommited
}

@Entity
public class One extends AbsOne<Two> {
    private String oneConcreteProp;
//... getters, setters... are ommited
}    

//and some more, for the context
@MappedSuperclass
public abstract class AbsTwo<ONE extends AbsOne<?>, THREE extends AbsThree<?, ?>> {
    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "three_id")
    private THREE three;
//... getters, setters... are ommited
}

@Entity
public class Two extends AbsTwo<One, Three> {
    private String twoConcreteProp;
//... getters, setters... are ommited
}    

After these entities are enhanced by bytebuddy/hibernate, invoking getters for parameterized field (e.g. one.getTwo()) do not invoke $$_hibernate_getInterceptor(), so the relation is not lazily fetched.
Works as expected in latest wildfly.

Expected behavior

Hibernate interceptor is invoked, triggering lazy load.

Actual behavior

No response

How to Reproduce?

clone https://github.com/mapuci/hibernate-parameterized-mappedsuperclass
here you will find quarkus reproducer AND wildfly project, with same entities working normally.
With some of my additional insights in readme. :)

To reproduce, change directory to quarkus3-hibernate-parameterized-mappedsuperclass and run ./mvnw test.

Output of uname -a or ver

Darwin Matejs-MacBook-Pro-2.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000 arm64

Output of java -version

17 (tried with 21 also)

Quarkus version or git rev

3.10.1 (I also tried 2.0.3.Final, 3.2.0.Final, 3.8.0)

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

Apache Maven 3.9.6

Additional information

No response

@mapuci mapuci added the kind/bug Something isn't working label May 19, 2024
@quarkus-bot quarkus-bot bot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels May 19, 2024
Copy link

quarkus-bot bot commented May 19, 2024

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

@yrodiere
Copy link
Member

Hey @mapuci ; thanks for reporting.

IIRC WildFly doesn't enable bytecode enhancement by default, so I don't think the WildFly reproducer is relevant.

Are you able to reproduce your issue in this test? https://github.com/hibernate/hibernate-test-case-templates/blob/main/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/QuarkusLikeORMUnitTestCase.java

If so, that's a bug in Hibernate ORM and we should fix it there. If not, it's indeed a bug in Quarkus itself.

@mapuci
Copy link
Author

mapuci commented May 21, 2024

Hi @yrodiere thank you for the reply.

About WildFly doesn't enable bytecode enhancement by default...
Sry, I misunderstood. Quarkus does bytecode enhancement with bytebuddy, WF just create proxies at runtime. With bytebuddy :D

But, results should be identical.

I will try to reproduce the issue with test mentioned above, I will let you know what I find.

@yrodiere yrodiere added the triage/needs-feedback We are waiting for feedback. label May 21, 2024
@mapuci
Copy link
Author

mapuci commented May 22, 2024

Hey @yrodiere
I managed to reproduce it in hibernate repo. I have created PR and an issue:

hibernate/hibernate-test-case-templates#387
https://hibernate.atlassian.net/browse/HHH-18151

I think that piece of code is cool. :)
image

I'm closing this issue, because it's not quarkus related.

@mapuci mapuci closed this as completed May 22, 2024
@yrodiere
Copy link
Member

Thanks a lot @mapuci!

@yrodiere yrodiere closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
@yrodiere yrodiere added triage/upstream and removed triage/needs-feedback We are waiting for feedback. labels May 22, 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 area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants