We're updating the issue view to help you get more done. 

Invalid SQL generated when using explicit and implicit joins

Description

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. 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

    1 2 3 4 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):

1 2 3 4 5 6 7 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

1 2 3 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.

Environment

PostgreSQL 9.5.4

Status

Assignee

Unassigned

Reporter

Piotr Findeisen

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.2.16
4.2.21

Priority

Major