Hi,
I am using a table per class strategy (<joined-subclass>).
For example:
@Entitiy
@Inheritance (strategy=InheritanceType.JOINED)
Class Person{
private long id;
private String name;
private int age;
......
}
@Entity
Class Pupil extends Person{
....
}
@Entity
Class Teacher extends Person{
.....
}
The purpose is to create a criteria/hql that returns the Person(or persons name) without joining to Pupil and Teacher.
The executed criteria is:
Criteria crit = session.createCriteria(Person.class);
crit.add(Restrictions.eq("age", 35));
crit.setProjection( Property.forName("name"));
Expected sql query is :
select name from Person;
But hibernate unfortunately always creates SQL queries which joins to the child elements.
For example:
select * from Person
left outer join Pupil
left outer join Teacher;
How can i avoid the joins?
Thanks for your help
|