Hibernate version:
3.2.4sp1
Mapping documents:
Entity relationship
Customer 1 -- *> Company 1---*> CompanyRevision
Hi all, I'm having a bit of trouble with HQL and any help would be appreciated. I have 3 classes, Customer, Company, and CompanyRevision. A Customer can have many Company objects, and each Company can have Many Revisions. I'm trying to select the latest revision for each company by joining through the Customer.id property. I have the following persisted data.
Code:
Customer (id 1)-->Company (id 1)-->CompanyRevision(id 1)
-->CompanyRevision(id 2)
-->Company (id 2)-->CompanyRevision(id 3)
-->CompanyRevision(id 4)
I have the following hql.
Code:
select revision from com.arocksoftware.arthur.model.CompanyRevision as revision inner join revision.company as company where revision.company.customer.id = :cId and revision = minelement(company.companyRevisions)
This returns to me CompanyRevisions with id 1 and 3, as expected. However I need the objects with id 2 and 4. Whenever I change by minelement function to use maxelement I receive id 3 and 4 in my result set. Here is my query that is not behaving as expected since its only returning the last 2 inserted company revisions, not the last inserted revision as I expect it to.
Code:
select revision from com.arocksoftware.arthur.model.CompanyRevision as revision inner join revision.company as company where revision.company.customer.id = :cId and revision = maxelement(company.companyRevisions)
Does anyone see something I'm missing? What seems wrong with this query?