title: Restrict mapping to get a specific one-to-one relationship for JPA-based sorting
body: <h2>Situation</h2>
  
  <p>I have two Hibernate entities, <code>Document</code> and <code>TitleTranslation</code>, with a one-to-many relationship, as there are multiple titles for a document, one for each language.
  <code>Document</code> has a property <code>id</code> and <code>TitleTranslation</code> references that through <code>document_id</code>.</p>
  
  <p>Therefore, to connect titles to documents, the natural solution would be a field as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>@JoinColumn(name = "document_id")
  List&lt;TitleTranslation&gt; translations;
  </code></pre>
  
  <h2>Goal</h2>
  
  <p>For sorting, I'm currently passing a <code>Sort</code> object to a JPA repository, e.g. <code>repository.findAll(mySort)</code>.
  The sort order property may reference transitive properties, such as <code>owner.firstname</code> (document has owner, owner has firstname).</p>
  
  <p>This works well as long as transitive properties are joined in a one-to-one fashion, but breaks down for one-to-many relationships as above:
  I'd like to sort by a document's title, but there's just a list of translations.
  However, since I'm just interested in one specific language, there is just one title in the list relevant to me, therefore a de-facto one-to-one relationship.</p>
  
  <p><strong>How can I achieve a one-to-one mapping to a translation of a certain language, so I could sort by e.g. <code>translationEn.title</code>?</strong></p>
  
  <h2>Partial solution</h2>
  
  <p>As it turns out, mapping through <code>OneToOne</code> results in one of the translations being picked (the first one?):</p>
  
  <pre class="lang-java prettyprint-override"><code>@OneToOne(mappedBy = "document")
  TitleTranslation translation;
  </code></pre>
  
  <p>This relies on a corresponding mapping in <code>TitleTranslation</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>@JoinColumn(name = "document_id", referencedColumnName = "id")
  Document document;
  </code></pre>
  
  <p>Now, I would like to indicate on the <code>translation</code> property that only translations with <code>language='en'</code> should be joined.
  I tried to use the <code>Where</code> annotation, but this only works in connection with one-to-many relationships.
  Thus, the following doesn't work as expected:</p>
  
  <pre class="lang-java prettyprint-override"><code>@OneToOne(mappedBy = "document")
  @Where(clause = "language='en'")
  TitleTranslation translation;
  </code></pre>