title: Hibernate: ordering a Set
body: <p>I have a class Person who has a set of Books. It is not meaningful in the particular case to have an ordered or sorted collection.</p>
  
  <p>Say now that I have a search page with a table showing the join of Person and Book. I want to be able to sort the results by fields from both Person AND Book, and then get a List from Hibernate, and iterate over it.</p>
  
  <p>Because the collection is a Set, the ordering of the Books has vanished (PersistentSet of Hibernate wraps a HashSet of Books, which is not ordered).</p>
  
  <p>So, with this approach I cannot have results also ordered by Book fields.</p>
  
  <p>If I change the collection from Set to List, my model is semantically incorrect. There is no meaning for keeping order in the model.</p>
  
  <p>Is there an approach to keep the ordering of Books? Perhaps there is a way for the PersistentSet to wrap a LinkedHashSet (which is ordered), where the order is defined by my search Criteria?</p>
  
  <p>Cheers!</p>