Hi,
my class (and table):
Code:
@Entity
public class ProcessState {
@Id
private int id;
private int processId;
private Date date;
private String state;
...
}
at each time the state of a process changes a new entry with current time and state is stored in db.
Now the problem is to get the states for a list of processIds to a given date. E.g. for each processId the entry with the greatest date less than the given date.
in sql i would do this with a left join:
Code:
SELECT *
FROM ProcessState ps
LEFT JOIN ProcessState ps2
ON ps.processId = ps2.processId
AND ps.date < ps2.date
WHERE ps2.processId IS NULL
AND ps.processId in ([list of processIds])
AND ps.date < [the given date];
But i can't figure out how to do this in a hibernate Criteria which i would prefer nor in HQL.
Regards,
Volker