title: Hibernate @Formula annotation causing sql exception errors when hibernate inserts table reference inappropriately
body: <p>I'm trying to use a Hibernate @Formula to import some calculated information into one of my Entity classes.  This is the code:</p>
  
  <pre><code>@Formula("(select max(site_visits.`date`) from site_visits where site_visits.siteId = id)")
  @Temporal(TemporalType.TIMESTAMP)
  private Date lastSiteVisit;
  </code></pre>
  
  <p>I've tried the query manually and it works fine.  The problem is that when I request the object, the SQL hibernate generates gets mangled: it insists on inserting its own table reference into the middle of my column reference expressions, so I get the following SQL error:</p>
  
  <pre><code>Unknown column 'site_visits.site0_.date' in 'field list'
  </code></pre>
  
  <p>Any idea how to fix this?</p>