OK, this looks mostly like (another) bug/unimplemented functionality in Hibernate.
Is it possible to map a Set
association in such a way that the "order by"
clause in HQL is respected?
For example, say you have 2 entities: PageEntity
and QuestionEntity
. A page has a Set.
How do I make the following HQL work:
from
PageEntity p
left outer join fetch p.questionEntities q
order by
q.orderIndex
What I don't want:
- to use sort in Java (we have "order by" in SQL so we don't have to do this!). SortedSet, Comparators etc. are out of the question
- to map it as a List with a
<list-index>
. This will add the "order by" to all SQL queries, and I don't want this - to use a
<set order-by="orderIndex">
because again, this will be applied to all queries
Debugging, I see that the implementation of Set that is being used is org.hibernate.collection.PersistentSet
which wraps a Set
. The implementation of the wrapped Set
is HashSet
. I would expect Hibernate to be smart enough to use a LinkedHashSet
instead, so that it can honor my "order by
" HQL clause.