Is it possible to convert the following into HQL 3.0.5 using any approach? Subqueries, outer joins with predicates, etc?
SELECT c.case_id,
(SELECT MAX(a.begin_date)
FROM assignment a
WHERE a.case_id = c.case_id)
FROM case c
The relationship between case and assignment is 1 to many. The intent of the query is to return all cases and their most recent assignment begin date, if one exists.
I’m having difficulty finding exactly what Hibernate 3.0.5 supports and what it doesn’t but I’ve seen indications that it only supports subqueries in the WHERE.
EDIT: If no assignment exists for a given case, the case_id should still return and the assignment begin date returned should be null.
Firstly, your SQL query can be rewritten with
JOINandGROUP BYinstead of subquery:In this form it can be easily converted to HQL, something like this (depends on mapping):