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