I've got a critical bug to fix for a sick colleague who used hibernate, which is new to me. A developers dream. ; )
The problem is that I need to put a join condition in a Criteria object. I know it's easy when using HQL, but I can't find any reference to it in the Criteria API or documentation.
This is what I need to get:
Code:
select count(*)
from ...
left outer join EVENTSOURCE es on r.ID_EVENTSOURCE=es.ID and es.ENABLED='Y'
where ...
The left outer join is easy, a condition in the where clause is easy, but how do I specifiy "es.ENABLED='Y'" in my join condition??
My current code doesn't work as hibernate says it has no reference to eventsource:
Code:
criteria.setFetchMode("eventsource", FetchMode.JOIN).add(Restrictions.eq("enabled", true));
But if I add a reference to eventsource in the criteria, he adds the restriction in the where clause instead of condition.
How should I solve this??