-->
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.  [ 6 posts ] 
Author Message
 Post subject: select distinct throws execption
PostPosted: Tue Dec 16, 2003 10:51 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
Hi there!

I'm trying to run the following query:

select distinct technician from Technician as technician
join technician.workingDays workingDays
where workingDays.salesorganisation = :so
order by technician.lastName, technician.technicianNo

If i call the query.iterate i get the following JDBC exception:

net.sf.hibernate.JDBCException: Could not execute query: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.


I tried to get around it by changing the query to this:

select distinct technician.lastName, technician.technicianNo from Technician as technician
...

But then i get an object array with lastName and technicianNo instead of a the technicians itself.

Any idea what i could do about it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:14 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Aren't you using .iterate() which does not select anything except object ID?

If no, what SQL is generated from your query? (check the log)
Are lastName and technicianNo columns there?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:22 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
thx mate, you just saved me 2 hours for coding a workaround which converts the object array back to a list with just the technicians.

It was the .iterate(). I'm using .list() now and it works fine.


Gavin, is this a bug or is hibernate supposed to behave like that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:25 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://www.hibernate.org/hib_docs/refer ... ng-data-s3

If you expect your query to return a very large number of objects, but you don't expect to use them all, you might get better performance from the iterate() methods, which return a java.util.Iterator. The iterator will load objects on demand, using the identifiers returned by an initial SQL query.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Oh its expected, I guess.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:59 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 9:50 am
Posts: 34
Location: Weiden Opf. / Germany
well i was using the iterate method because it's the only one that does utilize cache afaik.

well i suppose it doesn't make a a whole lot of a difference in performance, but it still would have been nice to use the cache since our technicians hardly ever change.


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