I found a way to simulate what we are looking for (I am using NHibernate but I presume something similar will work for hibernate)
This method creates a condition with the restrictions you require and then also allows for the case that no result exists.
Code:
public static ICriteria CreateLeftOuterJoin(ICriteria criteria, string associationPath, string alias, string key, params ICriterion[] restrictions)
{
ICriteria joinedCriteria = criteria.CreateCriteria(associationPath, alias, JoinType.LeftOuterJoin);
Conjunction conjunction = Expression.Conjunction();
conjunction.Add(Expression.IsNotNull(key));
foreach (ICriterion restriction in restrictions)
{
conjunction.Add(restriction);
}
joinedCriteria.Add(Expression.Disjunction()
.Add(conjunction)
.Add(Expression.IsNull(key))
);
return joinedCriteria;
}
and then you use like this
Code:
CreateLeftOuterJoin(criteria, "parent.Children", "child","child.Id",
Expression.Eq("child.Age", 12));
Sorry it's c#, I assume it wouldn't look to different in java though. The idea is to create the condition that you want, and then allow that condition or null.
The key parameter lets you specify a value to check for null on, I assume any property on the object will do.