-->
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.  [ 4 posts ] 
Author Message
 Post subject: Polymorphic HQL question ...
PostPosted: Thu Nov 18, 2004 7:36 pm 
Newbie

Joined: Thu Nov 18, 2004 7:24 pm
Posts: 2
I am using Hibernate 2.1.6 and the Table Per Subclass (joined subclass) method of inheritance mapping. If I have the following inheritance hierarchy ...

B -> Base Class
C -> Inherits from B
D -> Inherits from B

I can retrieve all instances by using HQL of the form ...

"from B as b"

However, if I attempt to do something like ...

"from B as b where b.class = C"

I get no results back, even though I have instances of both C and D.

The query compiles fine and executes. Does the above work with the Table Per Subclass method of inheritance?

I also tried supplying the "polymorphic association" as described in Chapter 8 of the docs. Ex.

<many-to-one name="base"
column="b"
class="B"/>

But it is not clear how this association gets set. Can someone please explain the reason for this association? I could not provide any explanatory text in the docs.

Thanks,
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 19, 2004 3:42 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
Joined-subclasses don't have a user defined discriminator value. Hibernate uses -1 for null, 0 for the base class, etc.. I am going to write a JIRA issue for this.
Anyway: why don't you simply query "from C" ?
The query "from B b where b.class=1" probably also works.

_________________
Dencel
- The sun has never seen a shadow -


Top
 Profile  
 
 Post subject: Polymorphic HQL Question
PostPosted: Fri Nov 19, 2004 11:06 am 
Newbie

Joined: Thu Nov 18, 2004 7:24 pm
Posts: 2
Yes, I had just thought that the joined-subclasses could be identified via this class name, since Hibernate obviously knows about it. Thanks for the tip on the integer. That indeed works.

Do you know what the polymorphic association in the docs is used for?

Thanks,
Brian


Top
 Profile  
 
 Post subject: Re: Polymorphic HQL Question
PostPosted: Fri Nov 19, 2004 11:09 am 
Regular
Regular

Joined: Tue Jan 27, 2004 12:22 pm
Posts: 103
gonegolfin wrote:
Do you know what the polymorphic association in the docs is used for?


No.

_________________
Dencel
- The sun has never seen a shadow -


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