-->
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.  [ 1 post ] 
Author Message
 Post subject: Newbie Mapping/Subclassing Question
PostPosted: Mon Nov 29, 2004 12:12 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 11:51 am
Posts: 31
Hello,
I’m using Hibernate 3 from CVS.
I’ve read the documentation multiple times but I think I’m going to need some help getting over this initial hurdle then hopefully other things will click.
Let’s say I wanted to model something like the following (collectively called “entities”):

corporation
|
subsidiary
|
department


So just to confirm, if each of these are going to be in a separate table, then I would want to use the <joined-subclass> element between these, right?

Now, let’s say I had a single table (called “ENTITY_INFO”) where I store information about each of these entities. Additionally, in my object representation of entity_info I want a reference to the associated entity. Since each entity table has its own primary key, I need a secondary column (called “entity_type” here) in entity_info in order to complete the relationship. So here’s my first stab at mapping the entity_info bit in Hibernate… so somebody please correct me if I’m wrong or if there’s a better way…. Thanks!

Code:
   <class lazy="true" name="entity_info" table="entity_info">
      <id name="oid">
         <generator class="native"/>
      </id>
      <property name=”phone”/>
      <property name=”num_people”/>
      <discriminator column="entity_type" type="integer"/>
      <subclass name="entity_info_corporation" discriminator-value="1">
         <many-to-one name="corporation" class="corporation ">
            <column name="entity_id"/>
         </many-to-one>
      </subclass>
      <subclass name="entity_info_subsidiary" discriminator-value="2">
         <many-to-one name="subsidiary " class=" subsidiary ">
            <column name="entity_id"/>
         </many-to-one>
      </subclass>
      <subclass name="entity_info_department" discriminator-value="3">
         <many-to-one name=" department " class=" department ">
            <column name="entity_id"/>
         </many-to-one>
      </subclass>
   </class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.