Uploaded image for project: 'Hibernate ORM'
  1. HHH-11363

Invalid SQL generated when using explicit and implicit joins


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Out of Date
    • Affects versions: 4.2.16, 4.2.21
    • Fix versions: None
    • Components: hibernate-core
    • Labels:
    • Environment:
      PostgreSQL 9.5.4
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      When trying to upgrade my application form Hibernate 4.2.15 to 4.2.25, Hibernate started to generate invalid queries (at least PostgreSQL says so) – maybe due to HHH-9305 Closed . The following is stripped down repro-steps. Please find attached the maven project reproducing the issue.

      repro steps
      • Entities: Book, Shelve, Author, Address with quite natural relationships
        • Book one-to-many Shelve
        • Book one-to-many Author
        • Author one-to-many Address
      • query
        select b.title as bookTitle, b.author.workAddress.text as authorAddress
        from Book b
        inner join b.author a
        inner join b.shelve s

      Generated SQL (reformatted, commented):

      SELECT book0_.title AS col_0_0_, address4_.text AS col_1_0_
      FROM Book book0_
      INNER JOIN Person person1_ ON book0_.author_id=person1_.id
      Address address4_
      INNER JOIN Shelve shelve2_ ON book0_.shelve_id=shelve2_.id -- BUG! here book0_ is undefined
      WHERE person1_.workAddress_id=address4_.id

      Error when running on PostgreSQL

      ERROR: invalid reference to FROM-clause entry for table "book0_"
        Hint: There is an entry for table "book0_", but it cannot be referenced from this part of the query.
        Position: 186

      Interestingly. this does not fail on H2, but I think PostgreSQL is right here.


          Issue links



              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: