Hi!
We have the following problem. We have a class JobGroup with an One-To-Many relation to Jobs. So, the jobGroup has a Vector of jobs.
Now, we want to fetch the Jobgroups and jobs in one query, ordering by jobGroup-id and by job-id.
The code-snippet should make it more clear:
Code:
public Vector<JobGroup> getJobGroupsAndJobs() throws Exception {
try {
Session s = ((TransactionScopedEntityManager)manager).getHibernateSession();
List<JobGroup> l = s.createCriteria(JobGroup.class)
.setFetchMode("jobs", FetchMode.JOIN)
.addOrder(Order.asc("id"))
//.addOrder(Order.asc("jobs.id"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
.list();
return new Vector<JobGroup>(l);
} catch (HibernateException e) {
ctx.setRollbackOnly();
log.error("Error fetching jobgroup/jobs list", e);
throw ResourceHelper.extractException(e);
}
}
This works fine, when just ordering by jobgroup-id. But then, the jobs are in the wrong order. So, how can we add an OrderCriteria for the job-Id?? Isn't this possible? When using the uncommented line ( ".addOrder(Order.asc("jobs.id"))" ), we get an unknown proterty exception.