Hibernate generates an inner join when a nullable many-to-one property is specified in the ORDER BY clause of an HQL statement.
If the property specified in the ORDER BY statement is nullable, then Hibernate should generate an OUTER JOIN to allow nulls in the result set. Instead, for whatever reason, Hibernate put's the property's table in the FROM clause, and JOINS the records with the parent table using a WHERE condition, which is basically an INNER JOIN. By performing the join this way, records with null values in the property being sorted upon are excluded from the query result set when they shouldn't be.
I also tried adding hibernate-mapping/class/many-to-one/@outer-join="true", and Hibernate generated the same SQL (inner join).
Example HQL: from Staff order by state.name
state is a many-to-one not-null="false" property of Staff.
Here's the SQL I expected to be generated:
left outer join STATE state1_ on staff0_.STATE_ID = state1_.STATE_ID
Here's the SQL that Hibernate generated:
staff0_.STATE_ID = state1_.STATE_ID
MS SQL Server Desktop Ed., Hibernate 3.1.2
As clearly outlined in the documentation, use of implicit joins unequivocally resolves to an inner join.
Use the explicit syntax and specify an outer join.