-->
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.  [ 8 posts ] 
Author Message
 Post subject: Complex Criteria/Subquery question
PostPosted: Thu Dec 01, 2005 7:19 pm 
Newbie

Joined: Thu Dec 01, 2005 6:36 pm
Posts: 8
Location: Chapel Hill, NC
New to the forums, scratching my head over this query and how to create a Criteria query....

SQL:

Code:
SELECT av.*
FROM AGENCYVEHICLE av
    inner join (
        SELECT DISTINCT MAX(CHANGEDATE) AS last_date,
        AGENCYVEHICLEID AS id
        FROM AGENCYVEHICLESTATUS
        GROUP BY AGENCYVEHICLEID
    ) M ON av.AGENCYVEHICLEID=M.id
    inner join AGENCYVEHICLESTATUS avs ON av.AGENCYVEHICLEID=avs.AGENCYVEHICLEID
        WHERE avs.VEHICLESTATUSLUID=2 AND avs.CHANGEDATE=M.last_date


Where I'm stuck is how to associate the inner subquery with the outer criteria query. The subquery is simple:

Code:
DetachedCriteria maxDate = DetachedCriteria.forClass(VehicleStatus.class);
ProjectionList projectionList = Projections.projectionList();
projectionList.add(Projections.max("changeDate"));
projectionList.add(Projections.groupProperty("vehicle"));
maxDate.setProjection(projectionList);

But how do I link this subquery to the original criteria? I've tried variations on the following:

Code:
criteria.add(Subqueries.propertyEq("statuses", maxDate));

but this generates the wrong sql.

Any suggestions, or any reasonable link to Criteria query resources? I've done two days of googling and searching here, and I'm not finding much that helps.

Thanks,

Paul Cooper
EMS Performance Center
Chapel Hill, NC
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 7:31 pm 
Newbie

Joined: Thu Dec 01, 2005 6:36 pm
Posts: 8
Location: Chapel Hill, NC
Forgot to post the version: Hibernate-Version: 3.0.3


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 7:33 pm 
Newbie

Joined: Thu Dec 01, 2005 6:36 pm
Posts: 8
Location: Chapel Hill, NC
Forgot to post the version: Hibernate-Version: 3.0.3


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 03, 2005 6:00 pm 
Newbie

Joined: Sun Jul 24, 2005 4:17 pm
Posts: 7
Paul,

Got an aswer to that?

I am trying something similar. The difference is that I am trying to inner join a different clas rather then a query.

H.Ceylan


Top
 Profile  
 
 Post subject: Similar problem
PostPosted: Wed Aug 09, 2006 8:41 am 
Newbie

Joined: Wed Aug 09, 2006 7:59 am
Posts: 9
Location: Nantes - France
Hi,

Have you got an aswer to that?
I have a similar problem.

--
Frantz D.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 1:41 pm 
Newbie

Joined: Thu Dec 01, 2005 6:36 pm
Posts: 8
Location: Chapel Hill, NC
Sadly, no, I have not found a solution to this problem.

Paul


Top
 Profile  
 
 Post subject: I found a solution !
PostPosted: Thu Aug 10, 2006 4:56 am 
Newbie

Joined: Wed Aug 09, 2006 7:59 am
Posts: 9
Location: Nantes - France
I just found a solution to my problem (cool) !

My problem and its solution are explained at http://forum.hibernate.org/viewtopic.php?p=2317841#2317841

Tell me if this could help you.

--
Frantz D.


Top
 Profile  
 
 Post subject: I found a solution !
PostPosted: Thu Aug 10, 2006 5:12 am 
Newbie

Joined: Wed Aug 09, 2006 7:59 am
Posts: 9
Location: Nantes - France
I just found a solution to my problem (cool) !

My problem and its solution are explained at http://forum.hibernate.org/viewtopic.php?p=2317841#2317841

Tell me if this could help you.

--
Frantz D.


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

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.