suppose I have the following 3 tables:
Facility id, name
Processor id, facility_id, enabled
Task id, facility_id, processor_id, name
I have queries that naturally join the task table with the processor table, but some tasks may not be linked to processors (i.e. task.processor_id may be null). I want to run a query that pulls all tasks in facilities that are linked to an enabled processor.
In other words, the query should look like this:
select task.name
from task, processor
where task.facility_id = processor.facility_id and processor.enabled = 1
I use @ManyToOne and @JoinColumn annotations to naturally link task to processor and to facility. There is also @ManytoOne and @JoinColumn on processor to facility.
How can I do it using hibernate criteria without resorting to native SQL?