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: Hybrid subclass / joined-subclass hierarchy?
PostPosted: Wed Aug 16, 2006 6:29 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
Longwinded example follows, thanks in advance to anyone that makes it through the whole thing, let alone feels nice enough to respond:

Let's say I've got an item hierarchy derived from a class called NamedObject. NamedObject is really just an abstraction for a named entity in my domain. The base class has a parent property (pointing to another NamedObject) and the subclasses on the tree have children collections specific to each subclass. For example:

Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
               assembly="Eg" namespace="Eg"
               default-lazy="false">
   <class name="NamedObject" table="NamedObjects">
      <id name="Id">
         <generator class="guid.comb"/>
      </id>
      <discriminator column="Type" />
      <property name="Name" length="256" not-null="true" />
      <many-to-one name="Parent" column="ParentId" />

      <subclass name="Server">
         <bag name="Databases" inverse="true" cascade="all">
            <key column="ParentId" />
            <one-to-many class="Database" />
         </bag>
      </subclass>      
      <subclass name="Database">
         <bag name="Tables" inverse="true" cascade="all">
            <key column="ParentId" />
            <one-to-many class="Table" />
         </bag>
      </subclass>
      <subclass name="Table" />
   </class>
</hibernate-mapping>


Ideally what I'd like is to use a <joined-subclass> here for a new type derived from Server called ServerConnectionDetails that should map to it's own table. I'd like a single column that's a PK/FK in this new table like <joined-subclass> does but NHibernate is complaining here about my mapping file, it looks like I can't have a <joined-subclass> child of a <subclass> element.

So I guess there's no way to set up a hybrid inheritence tree like this? If not, what's the next best way to go about this, or is there a cleaner way of doing what I'm attempting? I believe I need the NamedObjects table like I have it or else the code for the bulk of the functionality of my application gets incredibly ugly.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 16, 2006 6:51 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
I think your design is already ugly. you should implement the Composite pattern. AFAIK you can't implement mixed inheritance trees with hibernate. as joined-subclass is in fact using the one-to-one relationships, you can have a protected property in your implementation pointing to that table(class) and delegate to that class.

HTH,
radu


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.