I have a bidirectional many-to-many between Folder and Record and a class Test that extends Record.
Following HQL
Code:
select test.stringfield from Test test join test.folders folder where folder.id=?
creates following SQL
Code:
select test0_.stringfield as x0_0_ from S_Test test0_ inner join Record test0__1_ on test0_.id=test0__1_.id inner join folder_records folders1_ on test0_.id=folders1_.record_id inner join Folder folder2_ on folders1_.folder_id=folder2_.id where (folder2_.id=? )
Isn't the join on the collection table folder_records enough?
Maybe it is not possible for Hibernate to figure out that the join on Folder is not needed?
PS: In fact the join on Record is also not needed, but I can imagine that leaving that one out would make things too complex.
Ivo Houbrechts