How to order an HQL query using an object property in a collection?

Say I have a car with a radio, and the radio has a one-to-many relationship with Button. I want the unique names of all buttons in Ford cars, sorted by the name Button. Given how our relationship is set up, I can't figure out how to do this. Sort of:

select distinct elements(c.radio.buttons) from Car c where c.make = 'Ford' order by c.radio.buttons.name 

The last part is erroneous, of course. I am going to split pages into such pages, so I am trying to do this completely in a request.

The answer may include extracting the connection, but so far I have not been lucky. Thanks!

+4
source share
1 answer

HQL will be

 select distinct button from Car c join c.radio.buttons button where c.make = 'Ford' order by button.name 
+6
source

Source: https://habr.com/ru/post/1391763/


All Articles