title: How can I dynamically sort a collection property in JPA?
body: <p>We have the following JPA class:</p>
  
  <pre><code>@Entity
  class Supplier {
    // ... id property etc.
  
    @OneToMany
    @OrderBy("someProperty")
    private List&lt;Region&gt; regions;
  }
  </code></pre>
  
  <p>This works fine in the normal case. However, we have some multi-lingual data where the values are stored in properties like <code>nameEn</code>, <code>nameDe</code>, <code>nameZh</code>. The exact property to use depends on the logged in user. For example, a German speaking user should see the regions as if it had been annotated with <code>@OrderBy("nameDe")</code>.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I am aware I could sort the collection in my code after it has been loaded, but this makes pagination of the results quite difficult.</p>