title: Hibernate derived property with xml mapping
body: <p>I have a <code>Detectable</code> class with a <code>Revisions</code> set, which are Hibernate managed POJOs. I'm also mapping my entities using <em>hbm.xml</em> files. When user goes to <code>Detectable</code> management screen, I want him to see <code>Detectable</code> data into a table, which will also contain the last <code>Revision</code> done. However the complete set of revisions will only be available accessing the detail page of the detectable. </p>
  
  <p>My chance is to show the last revision date which will be loaded separately as an attribute with each <code>Detectable</code> instance. So I have something like that:</p>
  
  <p><strong>detectable.hbm.xml</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;set name="_Revisions" table="trevision" inverse="true" lazy="true"&gt;
      &lt;key&gt;
          &lt;column name="id_detectable" /&gt;
      &lt;/key&gt;
      &lt;one-to-many class="com.company.model.tasks.Revision" /&gt;
  &lt;/set&gt;
  
  &lt;property name="_LastRevisionDate"
          formula="select max(rev.start_date) from trevision rev where rev.id_detectable = _Id"
          type="date" /&gt;
  </code></pre>
  
  <p>That's not working and I have a SQL syntax error when hibernate tries to execute the query that is included in the <strong>formula</strong>. I've seen in different places that this property can be reached using <a href="https://stackoverflow.com/a/2986354/1199132">standard SQL</a> or <a href="http://www.techienjoy.com/hibernate-property-formula-attribute.php" rel="nofollow noreferrer">HQL</a> but I had failed with both of them. Also would it be possible to achieve the whole <code>Revision</code> entity (I mean the last revision) in order of the date only? </p>
  
  <p>Pool your ideas!</p>