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.  [ 5 posts ] 
Author Message
 Post subject: Is this inheritance strategy even possible?
PostPosted: Tue Oct 14, 2008 6:03 pm 
Newbie

Joined: Tue Oct 14, 2008 4:59 pm
Posts: 4
I have an interesting situation that I'm trying to solve with inheritance but the documentation doesn't seem to support what I'm trying to do.

I'm simplifying, but the basic situation is that our system has two database schemas. One (the "site" schema) is used at each individual installation of the program; there are many of them. The other (the "gateway" schema) is an aggregation schema; there is a single instance, and data from all the sites is aggregated into the gateway for global visibility, etc.

Many of the tables that exist on the site also exist on the gateway, but the gateway tables typically have some additional data elements that the sites do not have. An example:

At the site, the Item entity contains ItemId, ItemDescription, and something like 20 other properties. The gateway version of Item (call it "GatewayItem") includes all of the site's Item properties, plus some other ones, such as UnitPrice. The table is called "Item" in both schemas.

From an OO perspective, it makes sense for GatewayItem to derive from Item and simply define the additional properties. However, the inheritance strategies I see in the documentation seem to apply to separate entities within the same database, whereas in my situation I have two tables with the same name in different databases, one of which contains extra columns.

The intention is to invoke NHibernate with actual types; when I want to save a GatewayItem, I will call session.Save and pass a GatewayItem. I am simply trying to avoid having two classes with the same properties and mappings, and to allow our service layer to accept GatewayItem in methods that take an Item.

Is what I want to do even possible? I have the mapping written for Item, but I don't know where to even start for GatewayItem. I am trying to figure it out in parallel with this posting, in the hopes that someone here can save me some time. Apologies if I'm missing something obvious!

Thank you,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 2:00 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
I've never used NHibernate inheritance myself, so I can't give you a good answer.

But you could at least do the following:
Derive GatewayItem from Item in your Code, but don't tell NHibernate that it's derived (so just create a GatewayItem mapping with all Item and GatewayItem properties).

This is for sure not the best solution, but it should work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 7:51 am 
Newbie

Joined: Tue Oct 14, 2008 4:59 pm
Posts: 4
Thanks for the reply, and yeah, that's my last resort option, but I'm trying to avoid having to maintain the properties and mappings in two different classes for each entity.

I have a deadline on Friday so that may be the way I end up going, though, unless I can figure something out quickly. I will be able to refactor it after Friday but "getting it working" is my priority this week.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 7:51 am 
Newbie

Joined: Tue Oct 14, 2008 4:59 pm
Posts: 4
Thanks for the reply, and yeah, that's my last resort option, but I'm trying to avoid having to maintain the properties and mappings in two different classes for each entity.

I have a deadline on Friday so that may be the way I end up going, though, unless I can figure something out quickly. I will be able to refactor it after Friday but "getting it working" is my priority this week.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 7:54 am 
Newbie

Joined: Tue Oct 14, 2008 4:59 pm
Posts: 4
Sorry for the double (triple?) reply, but upon rereading I think I just understood your reply a bit better. I am currently using attribute-based mappings in my class files, but I think you're saying use an XML mapping for GatewayItem; that way, I have the mappings done twice but the properties are only defined once.

That's at least a step in the right direction. I will give that a try, and continue to watch this topic for other ideas.

Thanks!


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