-->
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: super-layer-class and hierarchies
PostPosted: Wed May 02, 2007 4:32 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
I'm working against a database where each table has a set of fields: version, lastModifedDate, lnsertDate, etc.

So all my classes will need these properties. then i have to map each one of these fields. ayeee!

is there a way I can take advantage of class hierarchy to achieve this. So that i would have a super-layer-class that would encapsualte all the common stuff. Then extend the class with busines entities. In this scenario how would i define my mapping so that i wouldn'th have to repeat it all the time?

public class DataClass
{
public int Version {get {return _version;} set{...}}
public DateTime {...}
etc.
}

public class Employe : DataClass
{
public string Name {...}
}

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 02, 2007 5:24 pm 
Newbie

Joined: Mon Apr 02, 2007 12:31 pm
Posts: 19
This approach will certainly work for your class structure (although you may want to reconsider).

For the mapping files, the only thing I can think of that has a chance of working would be to map everything using the table-per-subclass mapping strategy. Obviously this would severely limit your other inheritance possibilities.

edited to add You don't need to reflect the class hierarchy in the mapping. That is, it's possible to use a superclass for the common properties but not use any inheritance in the mappings. That way at least your classes would have some manner of code reuse, but your mapping files would still allow you complete flexibility for other inheritance needs.

I think in this case, your two best options are to make liberal use of copy and paste as you write the mappings, or to use a code generating tool to create either the mapped classes or the mapping files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 7:48 pm 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
The usual way to handle this is to form a value class around the common properties e.g. AuditDetails and then map them in each class as a component, see - http://www.hibernate.org/hib_docs/nhibe ... nents.html

_________________
Paul Hatcher
NHibernate Team


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 09, 2007 4:08 pm 
Beginner
Beginner

Joined: Wed May 02, 2007 12:24 am
Posts: 41
THanks,

THat was my original intention, but it meant that I had to copy paste the component everywhere.

Plus, my version field would have ended up in the component and I couldn't map it...that's maybe just something I was doing wrong.

Regards.


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.