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

Hibernate does not load lazy onetone entity attributes with activated batching #10722

Closed
Postremus opened this issue Jul 14, 2020 · 5 comments · Fixed by #11040
Closed

Hibernate does not load lazy onetone entity attributes with activated batching #10722

Postremus opened this issue Jul 14, 2020 · 5 comments · Fixed by #11040
Labels
area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE kind/bug Something isn't working
Milestone

Comments

@Postremus
Copy link
Member

Describe the bug
My entity has a lazy onetoone relationship to a child entity.
Attributes of the child entity are not read. They are kept null.
Eager onetoone work as expected.

After some debugging, I figured out that batching is the problem.
I removed quarkus.hibernate-orm.batch-fetch-size=100 from my configuration, and my child is loaded correctly.

Expected behavior
Attributes of my lazy loaded child onetone entity should get loaded.
Batching should work in all cases.

Actual behavior
Attributes of entities in a OneToOne relationship do not get loaded. They are null.
Any eager loaded onetone gets loaded correctly, with all attributes.

To Reproduce
Steps to reproduce the behavior:

  1. Download this reproducer project:
    hibernate-lazy-one-to-one.zip
  2. start it in dev mode by running mvn clean compile quarkus:dev inside the hibernate-lazy-one-to-one directory.
  3. Go to http://localhost:8080/hello/
  4. Set a Break Point at ExampleRepository#findName. And attach the debugger
  5. Go to http://localhost:8080/hello/1
  6. The debugger should now be inside the findName method.
  7. The name is still empty after line 26.
  8. Now remove quarkus.hibernate-orm.batch-fetch-size from the application.properties. Do everything again starting from step 3. Name now does get loaded correctly.

Configuration

quarkus.datasource.db-kind=h2
quarkus.datasource.username=sa
quarkus.datasource.jdbc.url=jdbc:h2:mem:test
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.transaction-manager.default-transaction-timeout=300s
quarkus.hibernate-orm.batch-fetch-size=100

Environment (please complete the following information):

  • Output of uname -a or ver:
    MSYS_NT-10.0 NANB7NLNVP2 2.10.0(0.325/5/3) 2018-06-13 23:34 x86_64 Msys
  • Quarkus version or git rev:
    1.6.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version):
    Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
    Maven home: C:\eclipse\tools\apache-maven\bin..
    Java version: 11.0.7, vendor: Azul Systems, Inc., runtime: C:\eclipse\tools\zulu11.39.15-ca-jdk11.0.7-win_x64
    Default locale: de_DE, platform encoding: Cp1252
    OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
@Postremus Postremus added the kind/bug Something isn't working label Jul 14, 2020
@quarkusbot quarkusbot added area/hibernate-orm Hibernate ORM area/persistence OBSOLETE, DO NOT USE labels Jul 14, 2020
@quarkusbot
Copy link

/cc @gsmet, @Sanne

@Sanne
Copy link
Member

Sanne commented Jul 15, 2020

@dreab8 could you check this out please?

@dreab8
Copy link
Contributor

dreab8 commented Jul 15, 2020

@Sanne sure

@Sanne
Copy link
Member

Sanne commented Jul 15, 2020

Apparently the bug is triggered when combining Enhanced Proxies with the PADDED or DYNAMIC batch strategies. Quarkus uses the PADDED strategy, while Hibernate ORM upstream by default is using LEGACY for backwards compatibility.

Unfortunately Enhanced Proxies had only been tested in combination with the ORM default, we'll fix this in Hibernate.

@Sanne
Copy link
Member

Sanne commented Jul 15, 2020

@Sanne Sanne changed the title Hibernate does not load lazy onetone entitiy attributes with activated batching Hibernate does not load lazy onetone entity attributes with activated batching Jul 19, 2020
dreab8 added a commit to dreab8/quarkus that referenced this issue Jul 27, 2020
dreab8 added a commit to dreab8/quarkus that referenced this issue Jul 28, 2020
dreab8 added a commit to dreab8/quarkus that referenced this issue Jul 28, 2020
@gsmet gsmet added this to the 1.7.0 - master milestone Jul 28, 2020
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

Successfully merging a pull request may close this issue.

5 participants