A many-to-many uses a join table in the middle that just contains pairs of IDs. When I reach across the many-to-many
just to get IDs I expect hibernate to get them from the join-table but, wastefully, it doesn't. Example SQL below.
Hibernate version:
hibernate-3.0.3.tar.gz
Name and version of the database you are using:
mysql Ver 12.22 Distrib 4.0.23, for pc-linux-gnu (i386)
The generated SQL (show_sql=true):
something like this
Code:
select count(*) from Left l inner join JoinTable j on l.id=j.left_id inner join Right r on j.right_id=r.id where r.id=11;
when SQL like this (one join less) would have done just as well:
Code:
select count(*) from Left l inner join JoinTable j on l.id=j.left_id where j.right_id=11;
(you see there is no need to go further than the JoinTable as that knows all there is to know about the IDs on its right)
Is this a known issue?