-->
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 "shallow" super class
PostPosted: Fri May 25, 2007 4:16 pm 
Newbie

Joined: Sat Mar 10, 2007 12:46 pm
Posts: 5
Hi all,

This is more of a design question than related to a specific NHibernate version.

I am implementing NHibernate in an enteprise app at my company.
All our domain objects inherit from a base class BrandShareObject which has properties Id, CreatedBy, CreatedOn etc.
The only reason they inherit is so I dont have to explicitly define these common properties on all objects.

This is an example of objects in two hierachies (an ActivityFile and an User):
public class ActivityFile : BrandShareObject
public class BinaryActivityFile : ActivityFile
public class TextActivityFile : ActivityFile
public class User : BrandShareObject

Currently these are stored in four tables:
ActivityFile, BinaryActivityFile, TextActivityFile and User.
The ActivityFile and the User tables contains the Id, CreatedBy, CreatedOn etc columns.
Hence the BrandShareObject is not known to the database.

How can I accomplish this with NHibernate? Obvisously I dont want a shared BrandShareObject table because then both Users and ActivityFiles will share the same identity number range.

OR is this bad design? Should I get rid of the BrandShareObject because it doesnt really belong in my domain model?

Hope to get some replies :)

/Niels


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 25, 2007 6:45 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
NHibernate will handle this automatically for you. Just map the Id, CreatedBy and CreatedOn as though they weren't inherited. NHibernate will figure the rest out.

As far as BrandShareObject meaning somthing in your Domain, I cant answer that for you without knowing more about the domain. I can tell you this, I have an Interface called IEntity<TId> which most of my aggregate roots implement. Well actually I have a concrete implementation called EntityInt32<TEntity> which implements IEntity<Int32>. This really just contains the Id property and implements equals and GetHashCode. but they all inherit from it so i dont have to keep creating an Int32 Id property. Does it have value in my domain? Not really, but it helps me interact with my ORM better. Sometimes technical details have to make their way into the domain, otherwise we wouldnt have Ids for hardly any of our domain objects. They are usually just to support persistence.

On a side note, I dont like have Audit information directly off of my domain object. I usually create a component for this called AuditInfo with the correct Audit proprties contained there. They way my domain objects dont get muddied up with audit data. Another nice thing is to have an Interace called IAuditable which can be trapped by an interceptor and the audit onfo can be populated automatically.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 26, 2007 4:01 am 
Newbie

Joined: Sat Mar 10, 2007 12:46 pm
Posts: 5
Excellent, I will try to do the mapping like that :)

It sounds interesting about the audit, do you have some sample code about this? Or link to an article?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 7:40 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Maybe this link will help with the audit info
http://forum.hibernate.org/viewtopic.ph ... ight=audit


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.