-->
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- combining tbl per hierarchy & tbl per subcl
PostPosted: Thu Sep 20, 2007 10:02 am 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
I created an ADO version of our O/R layer for the first phase of our project (this means we already have the database tables). I'm now in the process of providing an nHibernate version.

Note: The question is: How can I get an inheritance implementation that uses both tbl per hierarchy and tbl per subclass to work? Given that hibernate says that subclass and joined-subclass can't be combined, does that mean I have to create a table for each subclass?

Details:

We have a Device class hierarchy where there's an abstract Device class w/ common attributes for all devices. Each device (Router, Workstation, Switch, Hub, etc.) has its own concrete class that derives from the Device class. Most of these concrete classes add nothing of their own, inheriting behavior and properties from the Device class.

The database implements the inheritance with a combined approach where there's a Device table that has the attributes common to all devices (with a discriminator field) and other tables are created only for devices (such as Router and Switch) that have additional attributes (and these tables have a foreign key to the Device table). A further complication is that the discriminator is not directly in the Device table; instead we have a DeviceType table and the Device table has a foreign key to DeviceType's primary key field.

tblDevice: primary key = Identity (int) field
tblDeviceType: primary key = Identity (int) field; other columns: dtype (varchar)
tblRouter: primary key = Identity (int) field; has a foreign key to tblDevice for inheritance

Thanks,
Bill

_________________
metazone


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 2:51 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Karl Chu would be able to answer this better, but I think it should be possible to use the <join> element patch he implemented to allow the subclasses that need it to pull their extended properties from other tables. He has written about it several times before, you can do a search to find more info about how to compile it in and use it.

Also, it would seem that your DeviceType is rather static. It's kind of clunky, but you could just make the foreign key column the discriminator, and use the DeviceType PK directly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 6:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
The <join> element indeed solves this problem. The documentation is in the current trunk, but not yet published online. It is essentially the same as the Hibernate doc, see these links:


Note that the foreign key to tblDevice in tblRouter must be unique, otherwise, NHibernate would not know which row to use (it can only use one).

As to the DeviceType, as marcal had suggested, you probably have to use the DeviceType ID directly in your mapping file if the list of DeviceTypes are rather static.

See this post for more information on integrating NH-466 to 1.2GA:
http://forum.hibernate.org/viewtopic.ph ... 67#2365067

_________________
Karl Chu


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.