-->
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.  [ 7 posts ] 
Author Message
 Post subject: Component polymorphism (<subclass> within <componen
PostPosted: Mon Mar 29, 2004 7:02 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 7:27 pm
Posts: 30
Location: Minneapolis, MN, USA
I want to map a component with subtypes. The DTD seems not to support a <subclass> tag nested within <component>. Am I missing something? Is this just not supported? Is there a workaround?

Or am I stuck with writing a user type?

________________________________________________

In case you need more detail, here's my situation, boiled down and made humorous:
Code:
class Critter {
    BreathingStrategy getBreathingStrategy();
     ...
}
interface BreathingStrategy {
    void breathe();
}
class Lungs implements BreathingStrategy {
    Set<Alveolus> getAlveoli();
    ...
}
class Gills implements BreathingStrategy {
    List<Gill> getGills();
    ...
}

CRITTER:
    BREATHING_STRATEGY
     ...
ALVEOLI:
     CRITTER_ID
     ...
GILL:
     CRITTER_ID
     ...

I'd want to map this roughly as follows:
Code:
<class name="Critter">
    <component name="breathingStrategy" class="BreathingStrategy">
       
        <discriminator column="BREATHING_STRATEGY" type="integer" />

        <subclass name="Lungs" discriminator-value="0" >
            <set name="alveoli">
                <key column="CRITTER_ID" />
                <one-to-many class="Alveolus" />
            </set>
        </subclass>
       
        <subclass name="Gills" discriminator-value="1" >
            <set name="alveoli">
                <key column="CRITTER_ID" />
                <one-to-many class="Gill" />
            </set>
        </subclass>
    </component>
</class>

For the sake of this example, the different breathing strategies aren't supposed to know about each other, and the implementation Critter should be completely decoupled from all BreathingStrategy implementations. So I can't cheat by putting both Lungs and Gills on Critter internally, and then just exposing one or the other.

Thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 9:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A component is just a wrapper for several properties, It cannot be subclassed.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 11:13 am 
Beginner
Beginner

Joined: Thu Nov 06, 2003 7:27 pm
Posts: 30
Location: Minneapolis, MN, USA
emmanuel wrote:
A component is just a wrapper for several properties, It cannot be subclassed.


Well yes, that is clearly the case now. But why does this need to be so? There's no reason of logical consistency that I can see -- allowing component subclassing would make perfect sense, and seems like the only reasonable way of handling the case I laid out above.

If you can come up with a good alternative, I'm all ears!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can easily write a UserType that does this. Or you might like to create a patch to allow <component-subclass>es (this is not very hard).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 29, 2004 2:51 pm 
Beginner
Beginner

Joined: Mon Mar 08, 2004 6:09 pm
Posts: 20
I'm interested on this topic, can you give me some tips or readings on how to do it??

Thank you!


Top
 Profile  
 
 Post subject: Re: Component polymorphism (<subclass> within <componen
PostPosted: Fri Jun 19, 2009 12:07 pm 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
I also wanted this ability and couldn't do it. As a workaround, I tried to create a one-to-one relationship with a shared key, but couldn't figure out how to get a shared key without a back reference. I'd be really nice if component sub-classing just worked.


Top
 Profile  
 
 Post subject: Re: Component polymorphism (<subclass> within <componen
PostPosted: Thu Oct 01, 2009 6:18 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Any news on this ?
I am looking for examples on how to realize this with a UserType.


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