Skip to content

Hibernate batch-fetching seems to be broken in some situations where it works with pure Hibernate #41115

@lbilger

Description

@lbilger

Describe the bug

It seems that any database query executed after the one that loads the entity makes
the entity no longer eligible for batch fetching of lazy associations or element collections.

Expected behavior

Batch fetching should apply regardless of other queries being issued.

Actual behavior

Batch fetching is not applied if a query - even an unrelated one - is issued after the entity is loaded.

How to Reproduce?

Clone https://github.com/lbilger/quarkus-hibernate-batch-fetch-reproducer and run ./mvnw test.

Watch the console output. The ExampleEntityQuarkusTest will fetch
the anElementCollection of each ExampleEntity individually, while the ExampleEntityStandaloneTest will
fetch all in one batch.

Output of uname -a or ver

Darwin xyz 22.6.0 Darwin Kernel Version 22.6.0: Tue Nov 7 21:42:24 PST 2023; root:xnu-8796.141.3.702.9~2/RELEASE_ARM64_T6020 arm64

Output of java -version

openjdk version "21.0.2" 2024-01-16 OpenJDK Runtime Environment GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30) OpenJDK 64-Bit Server VM GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)

Quarkus version or git rev

3.11.1

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

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: /Users/xyz/.m2/wrapper/dists/apache-maven-3.9.6-bin/3311e1d4/apache-maven-3.9.6 Java version: 21.0.2, vendor: GraalVM Community, runtime: /Library/Java/JavaVirtualMachines/graalvm-community-openjdk-21/Contents/Home Default locale: de_DE, platform encoding: UTF-8 OS name: "mac os x", version: "13.6.3", arch: "aarch64", family: "mac"

Additional information

This is not related to native build. I'm not sure if the problem is in Quarkus or in Hibernate itself, but as the test shows, a pure Hibernate setup works. The only difference I can see except for Quarkus being involved is the transaction management (JTA in Quarkus vs. resource-local in the pure Hibernate setup).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions