-->
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.  [ 4 posts ] 
Author Message
 Post subject: hql question (joins)
PostPosted: Mon Dec 19, 2005 6:19 pm 
Newbie

Joined: Mon Sep 12, 2005 3:36 pm
Posts: 5
Hi,
i've got the following hql query (running this using springs hibernate template)

FROM ClientId ci,ClientId ci2
WHERE ci.caisiId=? AND ci.groupId = ci2.groupId
ORDER BY ci.groupPosition

this does what i want, but it returns a list of 2 element arrays, not just the list of ClientIds

any ideas on how to get this to just return a single list of ClientId object where the groupId property is the same, and i pass in the caisiId as the parameter

thanks


Top
 Profile  
 
 Post subject: Need joins?
PostPosted: Mon Dec 19, 2005 9:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
The logic there looks odd. You want to get all ClientIds where the caisiId is as speicfied, and the groupId is the same as any other ClientId? Or maybe you want all ClientIds which share a groupId with any ClientId with the given caisiId? Or is it that you want all ClientIds which have the given caisiId, so long as there's another ClientId with the same caisiId and groupId?

Either way, you want joins, not "FROM ClientId ci, ClientId ci2". That syntax is what's creating the list with two elements. Whatever about the rest of the query, the FROM should only have a single ClientId if all you want returned is a list of ClientIds.


Top
 Profile  
 
 Post subject: Re: Need joins?
PostPosted: Mon Dec 19, 2005 9:36 pm 
Newbie

Joined: Mon Sep 12, 2005 3:36 pm
Posts: 5
tenwit wrote:
The logic there looks odd. You want to get all ClientIds where the caisiId is as speicfied, and the groupId is the same as any other ClientId? Or maybe you want all ClientIds which share a groupId with any ClientId with the given caisiId? Or is it that you want all ClientIds which have the given caisiId, so long as there's another ClientId with the same caisiId and groupId?

Either way, you want joins, not "FROM ClientId ci, ClientId ci2". That syntax is what's creating the list with two elements. Whatever about the rest of the query, the FROM should only have a single ClientId if all you want returned is a list of ClientIds.



ya, it's pretty messed up :)

I want to get all ClientId objects that share a common groupId and one of them has the caisiId = ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 9:43 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I suppose that this must be possible with a HQL query, but I've never investigated that. It works well with sql-query, so that's what I use:

Code:
<sql-query name="ClientIDByCaisiAndGroup">
    <return alias="ci" class="ClientId"/>
    select {ci.*}
    from ClientId ci
    inner join ClientId ci2 on ci.groupId = ci2.groupId
    where ci.caisiId=?
    order by ci.groupPosition
</sql-query>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.