-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Help with HQL query minelement and maxelement
PostPosted: Tue Jun 05, 2007 2:12 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.