title: Hibernate Complex Join
body: <p>So we have 2 objects which each map to a db table.</p>
  
  <pre><code>public class Dispute {
    private Long disputeSeqNo;
    private List&lt;StatusInfo&gt; statusInfos;
  }
  
  public class StatusInfo {
    private Long statusSeqNo;
    private Date createdDt;
    private String statusCd;
    private Dispute dispute;
  }
  </code></pre>
  
  <p>A Dispute can have 0 or more StatusInfo's associated with it.</p>
  
  <p>Currently hibernate is returning all the StatusInfo objects for every Dispute.  While in some cases this is desired.  However I have a use case where:</p>
  
  <ul>
  <li>I only need to display the most recent StatusInfo for each Dispute.</li>
  <li>Additionally on this same display I need the ability to sort by the most recent StatusInfo.statusCd value.  This sort needs to happen at the database, since my display is paginated (using hibernate pagination facilities). (It's really not an option to sort the data after retrieval as there will be many many rows of data.)</li>
  </ul>
  
  <p>I know using just plain SQL I can do this, struggling to translate this into HQL.</p>
  
  <p>Any thoughts on how to solve this with HQL?  Where I still get back:</p>
  
  <pre><code>List&lt;Dispute&gt;
  </code></pre>
  
  <p>Appreciate your feedback.</p>
  
  <p>Thanks!</p>