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: Newbie help with class inheritance
PostPosted: Thu Jun 14, 2007 11:35 am 
Newbie

Joined: Thu Jun 14, 2007 11:26 am
Posts: 16
I'm just getting started with NHibernate and was looking for some help with inheritance. I've looked over some other posts but could not figure out what to do.

Here's the scenario. I have 2 database tables, NewUser and User. NewUser stores temporary user information when a user first signs up for the app. Once they have been confirmed the data is moved to the User table as well as active directory which is used for authentication purposes. The tables contain the following:

New User
EmailAddress
FirstName
LastName
CompanyName
JobTitle
Address info (eg. Street, province, etc)
Customer specific info (eg. customer #)
Industry types
RegistrationDate

User
EmailAddress
FirstName
LastName
CompanyName
CreatedDate
ModifiedDate
ModifiedBy

Everything else in the User table is stored in AD.

In my .NET code I have a UserBase class which contains all common properties (Eg. name info, etc). Each subclass, User and NewUser, inherits from UserBase include their specific properties.

How do I map this in NHibernate? The inheritance is in my C# code, not in the database.

Thanks for any help.[/u]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 12:24 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Other than the fact that they share some properties, NewUser and User seem very distinct, and UserBase really just seems to be a quick code re-use shortcut for you, rather than a deeper approach to inheritance sematics. That is, there doesn't seem to be any real way to ascribe the "is-a" relationships from the child classes to UserBase. Even their tables have no relationship other than sharing a few column names.

So, would it really be that damaging to your application use to map NewUser and User as distinct classes, and forego the inheritance semantics in NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 12:43 pm 
Newbie

Joined: Thu Jun 14, 2007 11:26 am
Posts: 16
Thanks for the quick response.

No, you're absolutely right. The 2 user types are very distinct and the UserBase class is just for code reuse. So it wouldn't be damaging at all to forego NHibernate's inheritance.

So, if I'm not worrying about any NHibernate-esque inheritance, how do I map, say, the User class. Do I need to include all the properties for both the User and UserBase class in the User.hbm.xml file or do I need to specify anywhere in the mapping file that User extends UserBase?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 18, 2007 11:54 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
colinhumber wrote:
...Do I need to include all the properties for both the User and UserBase class in the User.hbm.xml file or do I need to specify anywhere in the mapping file that User extends UserBase?


Only the former.

There may also be some issues with proxies for lazy initialization. Make sure everything that needs to be is virtual.


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.