-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Can not avoid joins to child elements
PostPosted: Tue Aug 28, 2007 9:00 am 
Newbie

Joined: Tue Aug 28, 2007 8:06 am
Posts: 1
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 6:43 am 
Newbie

Joined: Tue Dec 05, 2006 3:00 am
Posts: 15
Yes! Am also facing same problem here. Can any one give solution for this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 20, 2007 7:00 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
Java Persistance queries are always polymorphic (JPA spec 4.4.8). If you don't want polymorphism you can't use entity inheritance. You have to model it instead as a one-to-one relationship between Pupil <-> Person and and Teacher <-> Person. So instead of Pupil 'is a' Person it becomes Pupil 'has a' Person. Not quite natural I agree. Not sure if there is a better way of doing this.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.