@amut, It may not fail executing the query, but the results returned are incorrect. If joining an entity without following a path – here: “thingStats” – hibernate treats it (appropriatedly, I think) like a cross-join, and the SQL generated is:
Note the on true. However, if you add the join criteria explicitly (I changed the name to ts2 to avoid confusion with Thing.thingStats):
select thing from Thing thing
left join ThingStats ts2 on ts2.thingPk = thing.pk
where ts2 is null or (ts2.rejectedCount = 0 and ts2.thingPk = thing.pk
It works. Here’s the generated SQL:
But I think as a workaround, simply testing the attribute, as I indicated previously, is simpler (and easier to understand). |