-->
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: Extremely Complex Object Chart
PostPosted: Thu Mar 25, 2004 3:57 pm 
Newbie

Joined: Thu Mar 25, 2004 2:59 pm
Posts: 6
I would like to thank anyone who helps in advance.

I have a webapp (think tomcat,jsp,jdbc, etc.), which I think could benefit from hibernate. It has not yet been deployed and the database backend can be changed to the object-per-table. The only problem I am having is that the object model for the data is extremely complex.

For instance, I have inheretance and for each level of inheretence I have added "hasa" relationship, which constitutes more data that is specific for that level of object. Each "hasa" object itself could be decended from another object. The saving grace is that the top level object has the primary key for the entire tree, which saves to, at this time, one table.

I know this is all highly diffuse and probably confusing so I will throw up some psuedo-code to show you how it works.

public class TopLevelObject {
private Integer ID;
private Integer Foreign_ID;
private String name;

//setter and getter functions here
}

public class SecondTierClass extends TopLevelObject {
private Vector stuff;
private MoreData data;

public void addToStuff(Object moreStuff) {...}
public Object[] getStuff() {...}
public void setMoreData(MoreData data) {...}
public MoreData getMoreData() {...}
}

public class ThridTierClass extends SecondTierClass {
//yes, this class has more specialzed data which is different than
//the MoreData but it can have both of them (they are functionally
//different but the data is exactly the same although MoreSpeicalizedData uses basically a sub-set of MoreData
private MoreSpecializedData

public void setMoreSpecializedData(MoreSpecializedData data) {...}
public getMoreSpeicalizedData() {...}
}

This is just a taste of the data object model that I am working with. I hope that I have not been too diffuse but I would appreicate any help with building the mapping configuration file. If you think this is a sperious question, please let a admin know so that it can be deleted. Thanks again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 4:12 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Use joined-subclass mappings to specify inheritance, many-to-one or one-to-one to specify the "has a" relationships.

Read the docs. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 4:22 pm 
Newbie

Joined: Thu Mar 25, 2004 2:59 pm
Posts: 6
greg_barton wrote:
Use joined-subclass mappings to specify inheritance, many-to-one or one-to-one to specify the "has a" relationships.

Read the docs. :)


I have been. I did not quiet understand the many-to-one and the one-to-many relationship. I will keep digging. I see something that might help in the FAQ that I did not see before.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 5:25 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Code:
<hibernate-mapping default-cascade="all">

    <class name="TopLevelObject" table="top_level_objects">

        <id name="id" type="long">
            <generator class="native"/>
        </id>
       
        <property name="name" type="string"/>
               
        <joined-subclass name="SecondTierClass" table="second_tier_classes">
               
            <key column="id"/>
               
            <list name="stuff">
                <index column="index"/>
                <one-to-many class="StuffElements"/>
            </list>
       
            <many-to-one name="data" class="MoreData"/>
           
            <joined-subclass name="ThirdTierClass" table="third_tier_classes">
               
                <key column="id"/>
               
                <many-to-one name="specializedData" class="MoreSpecializedData"/>
               
            </joined-subclass>
           
        </joined-subclass>
       
    </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 5:48 pm 
Newbie

Joined: Thu Mar 25, 2004 2:59 pm
Posts: 6
Thanks! This clears things up from what I was looking at in the docs!

greg_barton wrote:
Code:
<hibernate-mapping default-cascade="all">

    <class name="TopLevelObject" table="top_level_objects">

        <id name="id" type="long">
            <generator class="native"/>
        </id>
       
        <property name="name" type="string"/>
               
        <joined-subclass name="SecondTierClass" table="second_tier_classes">
               
            <key column="id"/>
               
            <list name="stuff">
                <index column="index"/>
                <one-to-many class="StuffElements"/>
            </list>
       
            <many-to-one name="data" class="MoreData"/>
           
            <joined-subclass name="ThirdTierClass" table="third_tier_classes">
               
                <key column="id"/>
               
                <many-to-one name="specializedData" class="MoreSpecializedData"/>
               
            </joined-subclass>
           
        </joined-subclass>
       
    </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 6:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
Extremely Complex Object Chart


you will see that hibernate allows you to use very complex domain model.... welcome to hibernate world ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 25, 2004 8:26 pm 
Newbie

Joined: Thu Mar 25, 2004 2:59 pm
Posts: 6
delpouve wrote:
Quote:
Extremely Complex Object Chart


you will see that hibernate allows you to use very complex domain model.... welcome to hibernate world ;)


Thank you for the warm welcome!


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.