reynolr wrote:
Thus when hibernate constructs the SQL it has to do a join in order to provide the ability to select fields off of FooChild.
Thank you for your reply. I understand why (in general) the Hibernate makes the JOIN. But I need only common column! I do not FooChild nor FooEntity. I need only ID from the Foo table.
So far the only solution:
to use named query.Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@NamedQueries({ @NamedQuery(name = "allFooIds", query = "select id from FooEntity") })
public class FooEntity {
@Id private int id;
}
It's important to specify the column. Use only "from FooEntity" leads to LEFT JOIN with FooChild!
Used this query is simple:
Code:
List<Integer> fooIds = hibernate.getSessionFactory().getCurrentSession().getNamedQuery("allFooIds");
Using HQL has the advantage that Hibernate monitors and performs the change table and column names.
But why Hibernate does not same change in Criteria API, it is a mystery to me.