-->
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: Applying unique constraint on one col of primary key.
PostPosted: Thu Jun 21, 2007 3:14 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi

I am getting duplicate set rows for one query.But i want to display only
unique rows.

I thougt of doing queryResult.uniqueResult() but it seems it will apply
key on primary key

Here my primary key is : a+b+c+d

My requirement is : i want to get list of data of unique of b.

Is there any way to get this way .

Pls help me !! urgent !!


Thanks
Praveen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 21, 2007 1:34 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess your problem has nothing to do with unique constraint (in the db I mean). Didn't you use outer joins?

If so, call setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) before calling list().

HTH

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 3:32 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi ,

But i am using QueryObject rather than criteria to get the records from
database.

Pls could you tell is there any way todo this using QueryObject.

Pls help me !!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 11:31 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
"select distinct ..." could do it, but I seem to remember it is only available since Hibernate 3.2.

If you're using Hibernate < 3.2, then use something like :
Code:
List results = new ArrayList(new HashSet(yourQuery.list()));

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.