-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to use distinct with multiple columns in Criteria API
PostPosted: Wed May 26, 2010 2:49 am 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
Hi,

How can I write below query in criteria API?

Code:
select distinct col1, col2, col3
from some_table;


*Note that I want distinct to work on all 3 columns.

I can use Projections.projectionList() to specify 3 columns to fetch, but how can I apply distinct to all?

-Regards
Ajay


Top
 Profile  
 
 Post subject: Re: How to use distinct with multiple columns in Criteria API
PostPosted: Tue Jun 01, 2010 11:22 am 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
Try something like this
Code:
ProjectionsList projections = Projections.projectionList();
projections.add(Projections.count(col0));
projections.add(projection.count(col1...);

criteria.setProjection(Projections.distinct(projections))

see if this would work


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