-->
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: inheritance mapping
PostPosted: Mon Jan 09, 2006 2:03 am 
Newbie

Joined: Mon Jan 09, 2006 1:32 am
Posts: 3
Hello, Is it possible to map an entire inheritance hirachy?

for example:
Person -> User -> UserT //this are the classes whose objs need.
_____________-> UserC
______-> Contact

But for mapping this i should start from person class.
Is It possible to do this...
<class>
.......
<discriminator column="person_t"/>
<subclass name="User" discriminator-value="USER">
<discriminator column="user_type"/>
............
<subclass name="" dicriminator-value="USERT" />
<subclass name="" dicriminator-value="USERC" />
</subclass>
<subclass name="Contact" discriminator-value="CONTACT"/>
</class>

This is a 3 level example, could be more, but all the tutorials, docs, and books i been read, only shows 2 level inheritance. I thought that with nesting subclasses could be done the job.

But, if is immposible, i was thinking maybe if i start the mapping from de second level, from user, but Do i have to override the properties, methods, from Person?, or Hibernate take the inheritance, extends Person (take all from here)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 4:33 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
as far as i know you can have nested <subclass >
correct me if i am wrong

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 11, 2006 6:02 am 
Newbie

Joined: Wed Jan 11, 2006 5:21 am
Posts: 14
Yes it is possible. Please read the following example mapping.

Code:
        <class name="poc.user.model.User"
            table="USER" lazy="false" discriminator-value="USER">
                <id name="userID" type="string" length="20"/>
                <discriminator column="subclass" type="string"/>
                <property name="birthday"      type="date"/>
                <property name="firstname"     type="string" length="20" not-null="true"/>
                <property name="lastname"      type="string" length="20" not-null="true"/>
                <property name="middlename"    type="string" length="20"/>
                <property name="image"         type="binary" length="2048000"/>
                <component
                    name="homeAddress"
                    class="poc.user.model.Address">
                    <property name="street" column="homeStreet" type="string" length="100" not-null="true"/>
                    <property name="city" column="homeCity" type="string" length="30" not-null="true"/>
                    <property name="state" column="homeState" type="string" length="30"/>
                    <property name="zip" column="homeZip" type="string" length="10"/>
                    <property name="country" column="homeCountry" type="string" length="2" not-null="true"/>
                </component>
               
                <list
                    name="roles"
                    table="userRoles"
                    lazy="false">
                    <key column="userID" not-null="true"/>
                    <list-index column="roleIndex"/>
                    <composite-element class="poc.user.model.Role">
                        <property name="name" length="10"/>
                        <property name="description"/>
                    </composite-element>
                </list>
               
                <subclass name="poc.user.model.Admin"
                    discriminator-value="Admin">
                        <property name="equipment" type="string"/>
                        <subclass name="poc.user.model.Manager"
                            discriminator-value="Manager">
                            <property name="car" type="string"/>
                        </subclass>
               </subclass>
               
        </class>


In this mapping I defined subclass hierarchy User->Admin->Manager

The only thing you should notice is that it only creates one table "User". It will contain all the columns from User, Admin, and Manager objects.

Kind regards,
Roy


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.