-->
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: polymorphism="explicit"
PostPosted: Fri Sep 02, 2005 9:48 am 
Beginner
Beginner

Joined: Wed Jul 06, 2005 4:51 pm
Posts: 27
How does polymorphism="explicit" work? Does this enable only base class loading and instantiation?

If I have
Class A {
}
Class B extends A {
}

And when I set explicit polymorphism

<class name="A" table="a" polymorphism="explicit">

</class>

<joined-subclass name="B" table="b">

</joined-subclass>

If I use A.class with Criteria, I am getting instnace of B. Is there a way to get only instance of A. And get B only when I specify B.class?


Top
 Profile  
 
 Post subject: Re: polymorphism="explicit"
PostPosted: Fri Sep 02, 2005 10:20 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
If you specify the superclass, you will get all subclasses. If you specify a subclass, you will get only those subclasses.

I don't know of a way to only get the superclass objects.

I believe the assumption here is that the superclass is abstract and isn't used by itself.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 12:33 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
Honestly, I've been frustrated by this at times... but when it comes down to it, I find that I'm doing something lame when I need to query concrete instances of a base class directly. When I need that, I tend to go ahead and create an abstract base class and two subclasses.

If A extends B, then asking for all the B's which aren't A's is essentially like doing instanceof in hql.

To answer the question you actually asked, I believe polymorphism="explicit" does actually work, but then you won't be able to query for all of the B's and A's in one shot... I definitely prefer the abstract base class approach.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 1:12 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
I think you're correct that it works fine for <subclass> but <joined-subclass> works a bit differently.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


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.