-->
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: distinct and order by
PostPosted: Thu Sep 22, 2005 5:04 am 
Beginner
Beginner

Joined: Thu Jun 30, 2005 5:07 am
Posts: 33
Hi,

I am using Hibernate 3. I have a complex query that looks like that:
select setting from Device device inner join device.supportedSettings setting inner join setting.settingType type where
device.manufacturer = 2 and type = 1 order by setting.name"

The problem is that I am getting duplicate results. I put the distinct (select distinct setting from…). However I get an exception “ORDER BY item should be in the SELECT DISTINCT list”. What can I do?


Top
 Profile  
 
 Post subject: Re: distinct and order by
PostPosted: Thu Sep 22, 2005 12:37 pm 
Beginner
Beginner

Joined: Fri Aug 13, 2004 3:07 pm
Posts: 44
eranhauser wrote:
Hi,

I am using Hibernate 3. I have a complex query that looks like that:
select setting from Device device inner join device.supportedSettings setting inner join setting.settingType type where
device.manufacturer = 2 and type = 1 order by setting.name"

The problem is that I am getting duplicate results. I put the distinct (select distinct setting from…). However I get an exception “ORDER BY item should be in the SELECT DISTINCT list”. What can I do?


I used to get thi error which is actually a SQL thing. Just put setting.name in the select clause alongwith distinct so you query would be

Code:
select distinct setting, setting.name .......


Hope it helps.

_________________
Thanks
Sameet


Top
 Profile  
 
 Post subject: Any workaround?
PostPosted: Tue Feb 12, 2008 12:01 pm 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
I have the same problem. Sure I could add the ordering column to the select clause, but then list() will return a list of Object[] arrays rather than a list of my entities. :-(

Is there any hidden feature here to make Hibernate add the column to the actual SQL string, but not return it???
Something like "select distinct entity, sortTable.sortColumn as NULL ..."


Top
 Profile  
 
 Post subject: Re: Any workaround?
PostPosted: Tue Feb 12, 2008 12:17 pm 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
mate wrote:
Is there any hidden feature here to make Hibernate add the column to the actual SQL string, but not return it???
Something like "select distinct entity, sortTable.sortColumn as NULL ..."

Well. When I looked in another direction I found
Code:
query.setResultTransformer(new RootEntityResultTransformer());


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.