Hi Cathy,
I can't tell exactly what you're trynig to accomplish from this query but it looks like you want something similar to an example in the Hibernate documentation:
Code:
select count(payment), status.name
from Payment as payment
join payment.currentStatus as status
join payment.statusChanges as statusChange
where payment.status.name <> PaymentStatus.AWAITING_APPROVAL
or (
statusChange.timeStamp = (
select max(change.timeStamp)
from PaymentStatusChange change
where change.payment = payment
)
and statusChange.user <> :currentUser
)
group by status.name, status.sortOrder
order by status.sortOrder
Also you can't do subqueries or assign names in the select clause.
Cameron