title: How to use alias in @Formula
body: <p>So today I just run into a problem where @Formula is not working as I expected. Let say:</p>
  
  <p><strong>Database</strong></p>
  
  <pre><code>year |  X  |  Y 
  -----+-----+-----
  2010 |  A  |  10
  2011 |  A  |  20
  2011 |  B  |  99
  2009 |  C  |  30
  2010 |  C  |  40
  </code></pre>
  
  <p><br/>
  I want to get the year with the highest 'Y' and group by 'X', so I write a query like this</p>
  
  <pre><code>SELECT year
  FROM (SELECT
          year,
          MAX(y) OVER (PARTITION BY x ) max_y
        FROM TableB) q
  WHERE year = '2011' and x = 'A';
  </code></pre>
  
  <p><br/>
  <strong>So the result is</strong></p>
  
  <pre><code>year |
  -----+
  2011 |
  </code></pre>
  
  <p><br/></p>
  
  <p>Then I want to use it in entity so I create entity with @Formula</p>
  
  <pre><code>@Formula("(SELECT year FROM (SELECT b.year, MAX(b.y) OVER(PARTITION BY b.x) max_y FROM TableB b) q WHERE year = '2011' AND x = 'A')")
  private String yearWithHighestScore;
  </code></pre>
  
  <p>But Hibernate processes into:</p>
  
  <pre><code>(select entity0_.year as year1_8_ 
  from (select b.year as name, max(b.y) over(partition by b.year) entity0_.max_y from TableB b) entity0_.q 
  where entity0_.year=? and entity0_.x=?) as formula0_1_
  </code></pre>
  
  <p>You see Hibernate convert it into "entity0_.max_y" which is not correct because max_y is not a column of table TableB; it just an alias of calculated column</p>
  
  <p><strong>My question:</strong> Can we have any way to tell Hibernate it is alias of the column, it's not a column name itself ?</p>
  
  <p>Thanks</p>