title: Hibernate @OrderBy with referenced class
body: <p>I have a class say: "ClassA" which has a collection of "ClassB"</p>
  
  <pre><code>@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JoinColumn(name = "COLUMN_NAME")    
  private List&lt;ClassB&gt; lotsOfClasses;
  </code></pre>
  
  <p>"ClassB" has a mapped class "ClassC" using plain old mapping annotations:</p>
  
  <pre><code>public class ClassB {
  ...
    @ManyToOne
    @JoinColumn(name="AD_POINT_ID")
    private ClassC classC;
  ...
  }
  </code></pre>
  
  <p>How do I add an @OrderBy annotation to ClassA's collection to ClassB, so that the collection is ordered by the "name" property of ClassC</p>
  
  <p>Like so:</p>
  
  <pre><code>@OrderBy(clause="classC.name asc")
  </code></pre>
  
  <p>All I get are Oracle exceptions saying that classC is unknown.</p>
  
  <p>Any help here would be awesome, as its really bugging me at the moment.</p>
  
  <p><em>P.S. I should also mention that using the OrderBy annotation on the collection like this:
      @OrderBy(clause="classC asc")
  (i.e. without the .name on classC) I get a valid SQL statement, which uses the ID column (the primary key) of classC to order by.</em></p>
  
  <p>Cheers,
  Mark</p>