title: In hibernate is there a way to retrieve a list of entities ordered by a property of a many-to-one relationship object
body: <p>I have a many-to-one relationship as follows </p>
  
  <pre><code>    &lt;hibernate-mapping default-lazy="false" package="com.my.sample.data"&gt;
    &lt;class name="Person" table="person_table"&gt;
  &lt;!-- other stuff --&gt;
   &lt;many-to-one class="Company" column="p_id" fetch="join" insert="false" name="company" update="false" not-found="ignore" not-null="false" /&gt;
  </code></pre>
  
  <p>Company maps to company_table and has a property company_id. Is there a way to fetch a list of Person ordered by Company.company_id via hibernate. So when I query </p>
  
  <pre><code>  items = (List&lt;A&gt;) getSession().createCriteria(Person.class)                        
                          .add(Restrictions.in("person_id", pIds)
                          ).list();
  </code></pre>
  
  <p>So I end up with a list of Person ordered by company_id.
  The only addOrder syntax I found took a property name like </p>
  
  <pre><code>addOrder(Order.asc("person_id").` 
  </code></pre>
  
  <p>I could not find how to refer to a property name of a foreign object something akin to </p>
  
  <pre><code>addOrder.Order.asc("company.company_id")
  </code></pre>
  
  <p>Thanks.</p>