Hibernate @Formula annotation doesn't work
<p>I use @Formula annotation in Hibernate 4.3.7 but it doesn't load value.</p>

<pre><code>@Entity
@AccessType(Type.PROPERTY)
@Table(name = "ENTITY_B_TABLE")
public class EntityB extends AbstractEntity {
    //
    // ...
    //

    private EntityB parentEntityB;

    @Formula(value = "SELECT * FROM ENTITY_B_TABLE WHERE TYPE IN ('A', 'B', 'C') AND ROWNUM=1 CONNECT BY PRIOR PARENT_ID = ID START WITH ID = :id")
    public EntityB getParentEntityB() {
        return parentEntityB;
    }

    public void setParentEntityB(EntityB parentEntityB) {
        this.parentEntityB = parentEntityB;
    }

}
</code></pre>

<p>In that case I have an error:</p>

<blockquote>
  <p>Caused by: org.hibernate.MappingException: Could not determine type for: my.package.EntityB, 
  at table: ENTITY_B_TABLE, for columns: [org.hibernate.mapping.Formula(
  SELECT * FROM ENTITY_B_TABLE WHERE LEVEL_NAME IN ('A', 'B', 'C') AND
  ROWNUM=1 CONNECT BY PRIOR PARENT_ID = ID START WITH ID = :id )]</p>
</blockquote>

<p>In SQL "id" is id of current EntityB.
If I add a @Transient annotation to getParentEntityB method there are no mistakes but parentEntityB is null.
There is no column for parentEntityB in ENTITY_B_TABLE and we don't want create it, we want load it dynamicly. And we can garantee that parentEntityB is not null allways according to select.</p>

<p>Is there a better method to solve this problem?
(I also tried @Loader without success)</p>

<blockquote>
  <p>Try to move @Formula over the field. In my previous experience, I saw a > lot of them being only over fields. </p>
</blockquote>

<p>The result is same.</p>

<blockquote>
  <p>I found somethinf like this: forum.hibernate.org/viewtopic.php?f=1&amp;t=956537 - maybe that could help? 
  In short - @OneToOne may be required.</p>
</blockquote>

<p>With (@OneToOne or @ManyToOne) and without @Transient there is no exception, but parentEntityB still equals to null.</p>