-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Subclasses best practice
PostPosted: Sun Mar 23, 2008 5:39 pm 
Newbie

Joined: Sun Mar 23, 2008 5:28 pm
Posts: 6
Hi,

I have a class hierarchy as follows.

Abstact Class Object1 (name, date)
Class Object2 inherits Object1 (age)
Class Object3 inherits Object1 (IList Links)

Ive employed a one table per subclass mapping for the above. Object2 adds extra columns which are mapped as a joined subclass, this is fine and dandy. However Object3 doesn't add any extra columns but instead has a collection property of links from a Links table.

What is the best way to map this? Creating a table for Object3 seems pointless as they share the same Identifier as the Object1 table.

What I want is a joined subclass without a table but this sounds wrong.

Any help greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 5:58 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You can't mix subclass mapping strategies for a given class hierarchy, so either you need to have a table that has nothing other than a primary key or you need to use another mapping strategy.

An alternative is to use the table-per-class-hierarchy strategy where you have one table for both concrete subclasses. You add a discriminator column so NHibernate knows which rows represent which type and make any columns that are not present in the base class nullable.

There really isn't a best practice for this - it depends on your specific situation.

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 6:20 pm 
Newbie

Joined: Sun Mar 23, 2008 5:28 pm
Posts: 6
ok thanks for that. I would like to keep the table per subclass at the moment as I think its cleaner. Ill create the empty table for the time being. Is there a problem with having a joined-subclass with no property mappings say, if I want a concrete instance of the abstract class with no extra properties or collections?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 23, 2008 7:01 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Nope, no problem.

It might be a little less performant for your database if it's under heavy load as it needs to do the extra table lookup required by the join but with a clustered index on your primary key I don't imagine it's likely to hurt you unless you're in a high performance situation.

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


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