views:

1777

answers:

2

I have 2 entities: car and wheels (oneToMany) and I want to retrieve my car, with all the wheels and (this is the tricky part) ordered by wheels.location.

Select c from Car LEFT JOIN FETCH c.wheels order by c.wheels.location doesn't work: "illegal attempt to dereference collection".

Any idea how to do this and if this is possible in HQL?

A: 
SELECT DISTINCT c FROM Car LEFT JOIN FETCH c.wheels AS wheels ORDER BY wheels.location
AlfaTeK
A: 

Hmm. Think you might need to use an alias?

Select c from Car LEFT JOIN FETCH c.wheels wheel order by wheel.location
alasdairg