-->
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.  [ 6 posts ] 
Author Message
 Post subject: select after a property of subclass
PostPosted: Tue Nov 16, 2004 1:21 pm 
Beginner
Beginner

Joined: Sat Nov 13, 2004 7:21 pm
Posts: 24
Hi,

Does hibernate allow to select objects after some property of its subclass?

Let's say I have the object
Person {
String name;
int age;
...
}
and its subclass
Student {
String university;
...
}

can I generate a HQL query to get all persons which are students and with university="Harvard"?

I know about .class property for an object but I need somehow to access the property "university" for Person objects.

br


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 16, 2004 3:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
from Student s where s.university = "Harvard"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 8:02 am 
Beginner
Beginner

Joined: Sat Nov 13, 2004 7:21 pm
Posts: 24
Yes, but if I have an object that has a property of type Person and I want to make the following select:

from MyObject as obj
where obj.person.university="Harvard"

I got an exception saing property university is unknown for Person object.
I also tried to use the .class special property as follows:

from MyObject as obj
where obj.person.class = Student
and obj.person.university="Harvard"

but I got the same exception


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 9:20 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
What about:

select obj from MyObject obj, Student s where s.university = 'Harvard' and obj.person = s


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 10:06 am 
Beginner
Beginner

Joined: Sat Nov 13, 2004 7:21 pm
Posts: 24
when I use joins, subselects or select for multiple type of objects I get some proxies objects, with null values for all properties....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 17, 2004 10:22 am 
Beginner
Beginner

Joined: Sat Nov 13, 2004 7:21 pm
Posts: 24
alesj, thanks, it works now....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.