I'm using the Criteria api to request a collection (organizations) and sort it by a value (state_name) in an associated object (state). The state is related to the organization by a nullable column in the organization table (state_id).
The sort works well, except that it discards all organizations that have a null state_id. Is there a way to sort by state.state_name while retaining all organizations that don't have a state?
I'm not married to the Criteria api, but would prefer to use it if possible.
Here's what I'm doing:
Code:
Criteria orgCriteria = session.createCriteria(Organization.class);
// Select a collection of organizations based on organization name
orgCriteria.add(Restrictions.like("name",("%" + OrganizationName + "%")));
// Sort organizations by state_name
Criteria stateCriteria = orgCriteria.createCriteria("state");
stateCriteria.addOrder(Order.asc("state_name"));
theseOrgs = orgCriteria.list();