-->
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.  [ 5 posts ] 
Author Message
 Post subject: Querying w/Composit key
PostPosted: Thu Feb 26, 2004 8:12 pm 
Newbie

Joined: Thu Feb 19, 2004 10:25 pm
Posts: 16
I've looked and looked and cannot find any docs on how to form queries with composite keys. Could someone point me in the correct direction? In particular, I'd like to do a Select distinct on an class that has a composite key.

TIA,

_________________
-Scott-


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 11:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You need to use the id.field for the fields of the composite Key.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about doing something like this:
String query = "from com.test.myComposedIdClass c where c.id1= :id1 and c.id2 = :id2"

It looks too easy, sure i've misunderstood your problem


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 11:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
delpouve wrote:
what about doing something like this:
String query = "from com.test.myComposedIdClass c where c.id1= :id1 and c.id2 = :id2"

It looks too easy, sure i've misunderstood your problem



Excuse:
String query = "select distinct(c) from com.test.myComposedIdClass c where c.id1= :id1 and c.id2 = :id2"


Top
 Profile  
 
 Post subject: Thanks... Solved!
PostPosted: Sat Feb 28, 2004 1:41 pm 
Newbie

Joined: Thu Feb 19, 2004 10:25 pm
Posts: 16
In the end, this is what worked:

Collection list = session
.createQuery("select distinct location.comp_id.lsecurityId from Location as location").list();

The reason for makening it return a list is that it cannot return entity objects just string containing the name of the unique properity

_________________
-Scott-


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