-->
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.  [ 2 posts ] 
Author Message
 Post subject: Discriminator Question
PostPosted: Mon Jun 20, 2005 9:00 pm 
Newbie

Joined: Mon Jun 20, 2005 8:47 pm
Posts: 11
Hi,

I have two related tables with a one to many relationship.

I am using NHibernate's subclass definition to create entities based on the value of the foreign key column in the "many" table. This I can get to work fine - example mapping follows:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="XXX.BusinessEntities" assembly="XXX.ApplicationServices">

   <class polymorphism="explicit" name="ComboBoxEntry" table="ComboBoxes" discriminator-value="0">
       
        <id name="Id" column="CB_ID" type="Int32">
            <generator class="identity" />
        </id>

      <discriminator column="CB_CBN_ID" type="Int32" not-null="true"></discriminator>

         <property name="Description" column="CB_Description" type="String" length="50" not-null="true" />
         
      <subclass discriminator-value="3" name="Zone">
         <many-to-one name="ComboBox" column="CB_CBN_ID" insert="false" update="false"  not-null="true" />
      </subclass>

      <subclass discriminator-value="4" name="TrackType">
         <many-to-one name="ComboBox" column="CB_CBN_ID" insert="false" update="false"  not-null="true" />
      </subclass>

      <subclass discriminator-value="5" name="RaceType">
         <many-to-one name="ComboBox" column="CB_CBN_ID" insert="false" update="false"  not-null="true" />
      </subclass>

   </class>
</hibernate-mapping>


As you can see I create a Zone, TrackType and RaceType entity based on the CB_CBN_ID column.

What I dislike about this is the dependency on an actual value in the foreign key - what if the value is different between deployments (all primary keys are identity columns) ?

What I would like to do is refer to the code in the "one" table that relates to that discriminator value. For example, using ComboBox.Code - this removes the dependency on the identity column.

Is this possible? If so, can somone please post an example?

Thanks in advance,

Mike :)


Top
 Profile  
 
 Post subject: Follow Up
PostPosted: Tue Sep 27, 2005 11:50 pm 
Newbie

Joined: Mon Jun 20, 2005 8:47 pm
Posts: 11
Still waiting for a response on this one... :D


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