A filter condition for a many-to-many association is added to the where clause instead of to the left outer join on clause when doing a get by ID with eager join fetching. This means that the select returns no records, when there are associated entities, but they are all filtered out.
The example below generates this SQL:
BTW: createCriteria with ManyToMany association and Filter creates the correct SQL.
Example Test using above DBOs: testManyToManyFilterGet fails, while testManyToManyFilterGetAll succeeds.
The problem probably lies in LoadQueryJoinAndFetchProcessor.renderManyToManyJoin, which
which feeds the "where" condition,
while QueryJoinFragment.addJoin (correctly)
calls JoinFragment.addJoin(..., conditionsAndManyToManyFilters) for outer joins,
which feeds the "on".
(OuterJoinable.addManyToManyJoin -> ... -> QueryJoinFragment.addJoin)
This bug probably also exists in Hibernate 5 (same code in LoadQueryJoinAndFetchProcessor), but I did not test it.