• Post Reply Bookmark Topic Watch Topic
  • New Topic

EQL Struggle With DISTINCT and ORDER BY

 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I want to do something like this :


Where "sub" is a an entity reference in entity "main" that has a one to one relationship to main. The error I'm getting is :

"ORDER BY item should be in the SELECT DISTINCT list"

which I suppose makes a bit of sense. Is there a workaround for this?


 
Ankit Garg
Sheriff
Posts: 9591
34
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I don't know any workaround with a EQL statement, but you can always make the class that represents main.sub implement comparable and then sort the list that you get from the database query. I know this might be a performance problem, but this is the only workaround I can think of...
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why distinct?

You do not have to say "distinct main", if you hold your Main-Entities in a Set (HashSet) then no duplicates exists in your Set. Do not forget to override equals/hashCode for this Entity.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!