This is part of a series of posts about NHibernate Pitfalls. See the entire collection here.
Normally, in an HQL query, you can omit the select clause, that is, the two queries are identical:
However, if you add joins, then it’s a whole different matter:
Worse, queries q3 and q4 will not filter distinct root entities, meaning, you will get the cartesian product of Product x OrderDetail.
So, you will need to select the root entity (select p), plus add a distinct entity result transformer (Transformers.DistinctRootEntity) to get what you want:
This doesn’t happen with LINQ, it always performs a distinct root entity selection, but it also happens with Criteria and QueryOver.