title: hibernate derived properties with xml
body: <p>I have table called Student as Below</p>
  
  <pre><code>ID        NAME     DOB
  ---       ----     ---------
  1         A        2009-01-28
  2         B        2001-05-20
  </code></pre>
  
  <p>I am using derived properties to get the <strong>AGE</strong> from the dob as below in the hbm file </p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="com.arat.derived.Person" table="person" catalog="spring_db"&gt;
      &lt;id name="id" type="int"&gt;
          &lt;column name="id" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;property name="name" type="string"&gt;
          &lt;column name="name" /&gt;
      &lt;/property&gt;
      &lt;property name="dob" type="date"&gt;
          &lt;column name="dob" length="0" /&gt;
      &lt;/property&gt;
      &lt;property name="age" type="integer" column="AGE"
          formula="( select TIMESTAMPDIFF(YEAR,p.dob,NOW()) as AGE 
                       from person p where p.ID=ID)"&gt;&lt;/property&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>and my POJO class <strong>Student</strong> has all the property id,name,dob and age with setter and getter method.</p>
  
  <p>While fetching the data using load or get method I am getting the error</p>
  
  <pre><code> private static void loadPerson() {
      Session session = factory.openSession();
      Person person = (Person) session.get(Person.class, 0);
      System.out.println("Person : name " + person.getName() 
              + ", dob: " + person.getDob() + ", age : " + person.getAge());
  
  }
  </code></pre>
  
  <blockquote>
    <p>Hibernate: select person0_.id as id1_8_0_, person0_.name as name2_8_0_, person0_.dob as dob3_8_0_, ( select TIMESTAMPDIFF(person0_.YEAR,p.dob,NOW()) as person0_.AGE from person p where p.ID=person0_.ID) as formula0_0_ from spring_db.person person0_ where person0_.id=?
    Feb 07, 2015 7:20:22 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 1064, SQLState: 42000
    Feb 07, 2015 7:20:22 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'person0_.YEAR,p.dob,NOW()) as person0_.AGE from person p where p.ID=person0_.ID)' at line 1
    Feb 07, 2015 7:20:22 PM org.hibernate.event.internal.DefaultLoadEventListener onLoad
    INFO: HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: could not extract ResultSe**</p>
  </blockquote>
  
  <p>can you tell me where I am wrong?</p>