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: inheritence mapping and subclasses
PostPosted: Fri Aug 18, 2006 2:33 am 
Newbie

Joined: Thu Aug 10, 2006 10:08 pm
Posts: 12
Hi,

I have a database that has several rows attached to each table that contains data for auditing.
the table looks like this

Other stuff |.......| userName | DateChanged |

I am wondering if it is possible to create a mapping that would allow these fields to be in a PArent class.

ie. Public Abstract Class Audit {...}

Public Class OtherClass : Audit {...}

this would obviously take the code writing for each table out, which will save me a lot of time.

is this possible??
if so How would i add the mapping. I can not see how this fits with the 3 stratagies listed out in the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 20, 2006 9:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It is possible, but I don't think it's ideal, as you'll end up with a class hierarchy of unrelated classes. Putting classes into a hierarchy just because they share some fields isn't great. Better solutions would be to create a CompositeUserType for the userName and dateChanged columns, or to go with a variation on implicit polymorphism, or both.

The composite user type thing is well documented, you can read up on it in the hibernate ref docs, and presumably in the NHibernate ref docs too.

The implicit polymorphism thing works well in conjunction with the composite user type. Essentially, you create your superclass containing the composite class, and all your classes extend this, but you don't map the superclass. You map the normal classes in the normal way, specifying the composite user type in each mapping. Because each C# class extends the superclass, you never need to worry about writing extra code; and because the mappings don't extend a fake superclass, you don't risk confusing whoever will be maintaining your code in a few years' time.

_________________
Code tags are your friend. Know them and use them.


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.