Giter VIP home page Giter VIP logo

hibernate6joinfetchissue's Introduction

Possible hibernate 6 bug

Summary

  • after updating spring boot to 3.0.1 (which also updates hibernate to 6.1.6.Final) join fetching of nested entities does not work anymore when the nestedEntity reference is in an abstract superclass ("BodyPart") that uses @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  • the result is a LazyInitializationException when accessing fields in the nested entity although join fetch has been specified in the @Query

Requisites

  • entity ("Person") exists that has a field which is a set of other entities ("Set<Leg>")
  • these other entities are derived from an abstract super class ("Leg extends BodyPart")
  • the abstract super class' inheritance strategy is SINGLE_TABLE
  • the abstract super class has a nested entity ("NestedEntity") which has some fields

Reproduction

  • execute the test PersonPersistenceTest.shouldJoinFetchTheNestedEntitiesOfLegs
  • the test basically
    • creates and saves a Person with one Leg and that Leg has a NestedEntity
    • fetches the Person by findByIdJoinFetchLegsWithNestedEntity (a @Query method in the Repository). The query uses join fetch to specify that person->legs is fetched and also that legs->nestedEntity is fetched.
    • tries to access the nested entity via person->legs->nestedEntity->name

Observations in Hibernate 5.6.14.Final

  • the query created by findByIdJoinFetchLegsWithNestedEntity is working correct
  • it join fetches both the body_part and the nested_entity table
  • it uses a left OUTER join for that
  • it only defines the clause legs1_.discriminator='LegBodyPart' once

Observations in Hibernate 6.1.6.Final

  • the query created by findByIdJoinFetchLegsWithNestedEntity is NOT working correct
    • there is no second left join which would join the nested_entity table
    • it does NOT use a left join (not outer)
    • also, it is strange that there is a duplicate join clause l1_0.discriminator='LegBodyPart' and l1_0.discriminator='LegBodyPart'

hibernate6joinfetchissue's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.