title: @Formula Hibernate Annotation not evaluated
body: <p>i just found out about the <code>@Formula</code> Annotation in Hibernate, but cannot get it to work.</p>
  
  <p>I Tried using a hibernate Session to access the entites as well as a JPA <code>Entitymanager</code> with <code>persistence.xml</code>, in both cases my <code>@Formula</code> annotated field remains "null".</p>
  
  <p><strong>my Entity (copied from an Example):</strong></p>
  
  <pre><code>    @Entity(name = "Account")
      public static class Account {
  
      @Id
      @GeneratedValue( strategy = GenerationType.IDENTITY )
      private Long id;
  
      private Double credit;
  
      private Double rate;
  
      @Formula(value = "credit * rate")
      private Double interest;
  
      //Getters and setters omitted for brevity
      }
  </code></pre>
  
  <p><strong>My Test-Setup (initializing a Session an an entitymanager for Test cases):</strong></p>
  
  <pre><code>    private SessionFactory sessionFactory;
      private Session session = null;
      EntityManager em;
  
      @Before
      public void before() {
          EntityManagerFactory emf=Persistence.createEntityManagerFactory("test-pu");
          em=emf.createEntityManager();
  
          Configuration configuration = new Configuration();
          configuration.addAnnotatedClass(TestEntity.class);
          configuration.addAnnotatedClass(Account.class);
          configuration.setProperty("hibernate.dialect",
                  "org.hibernate.dialect.PostgreSQL94Dialect");
          configuration.setProperty("hibernate.connection.driver_class",
                  "org.postgresql.Driver");
          configuration.setProperty("hibernate.connection.url",
                  "jdbc:postgresql://localhost:5432/Archiv");
          configuration.setProperty("hibernate.hbm2ddl.auto",
                  "create");
          configuration.setProperty("hibernate.connection.username",
                  "postgres");
          configuration.setProperty("hibernate.connection.password",
                  "postgres");
          sessionFactory = configuration.buildSessionFactory();
          session = sessionFactory.openSession();
  
      }
  </code></pre>
  
  <p><strong>The persistence.xml for the entitymanager:</strong></p>
  
  <pre><code>    &lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt;
  
      &lt;persistence-unit name="test-pu" transaction-type="RESOURCE_LOCAL"&gt;
              &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
  
              &lt;class&gt;com.test.ORMTest$Account&lt;/class&gt;
              &lt;class&gt;com.test.ORMTest$TestEntity&lt;/class&gt;
              &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
              &lt;properties&gt;
  
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;
              &lt;property name="hibernate.show_sql" value="true"/&gt;
  
              &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
              &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/Archiv"/&gt;
              &lt;property name="hibernate.connection.username" value="postgres"/&gt;
              &lt;property name="hibernate.connection.password" value="postgres"/&gt;
  
              &lt;property name="hibernate.format_sql" value="true"/&gt;
  
              &lt;property name="javax.persistence.validation.mode" value="NONE"/&gt;
              &lt;property name="hibernate.service.allow_crawling" value="false"/&gt;
              &lt;property name="hibernate.session.events.log" value="true"/&gt;
          &lt;/properties&gt;
  
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>And last but not least, the Test Code:</strong></p>
  
  <pre><code> @Test public void emTest(){
  
          em.getTransaction().begin();
          Account account = new Account();
          account.credit=100.0;
          account.rate=0.1;
          em.persist(account);
          em.getTransaction().commit();
  
          em.getTransaction().begin();
  
          Account account1 = em.find(Account.class, 1l);
  
          Double d = account1.getInterest();
          System.out.println(d);
          em.getTransaction().commit();
  
      }
  
      @Test
      public void sessionTest() {
          Transaction transaction = session.beginTransaction();
          Account account = new Account();
          account.credit=100.0;
          account.rate=0.1;
          session.save(account);
          transaction.commit();
  
          transaction = session.beginTransaction();
          Account account1= session.get(Account.class, 1);
          Double d = account1.getInterest();
          System.out.println(d);
          transaction.commit();
      }
  </code></pre>
  
  <p>Both Cases print "null" for <code>d</code>.</p>
  
  <p>According to the examples both cases should work. Anyone firm with Hibernate to tell me where i went wrong ?:/</p>