Hi,
I'm using
Hibernate version:3.1 and I'm having real problems using detached criteria to produce sql with an outer join. I'm trying to get Hibernate to produce sql along these lines...
Code:
select
company.name,
outcome.name
from
WorkItems this
inner join Companies company on this.com_id=company.com_id
left outer join Outcomes outcome on this.o_id=outcome.o_id
where company.com_id = 'xxx'
I have included below a fragment of code that should show one of the ways that I have tried to get this to work, however I always end up with an inner join being generated. Please help, what am I doing wrong?
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(WorkItem.class);
criteria = criteria.createAlias("company","company");
criteria = criteria.add(Expression.eq("company.id", "xxx"));
criteria = criteria.createAlias("outcome", "outcome").setFetchMode("outcome", FetchMode.JOIN);
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.property("company.name"));
projectionList.add(Projections.property("outcome.name"));
criteria = criteria.setProjection(projectionList);
Criteria realCriteria = criteria.getExecutableCriteria(getSession());
realCriteria.list();
thanks
Jim