-->
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: Need discriminator recommendation for preexisting schema
PostPosted: Tue Nov 13, 2007 2:36 pm 
Newbie

Joined: Wed Oct 31, 2007 1:50 pm
Posts: 13
We have a 3rd party database (Oracle) that we cannot change as the application sitting on top is still very much in use. We are extending it though and have, thus far, been successful at using NHibernate with it.

I have run into a road block with one part. We have a table that represents an idea of Attributes. These attributes have a relationship to either Household, Person or Card (think of that as a Hierarchy in that People have cards and those people make up a household). The problem lies in that the AttributeValue table joins to either Household, Person or Card Id based on a CPHLevel column with either C (card), P (Person ), or H (Household ), but I wouldn't say that there should be three subclasses or joined classes for each permuation

So a select for the card's attribute values would look something like this (manually created):
Code:
select attdef.name, attval.value
from attributedetail attval
  inner join attributedefinition attdef on attval.attributeid = attdef.attributeid
  inner join card on attval.customerkey = card.id
where def.cphlevel = 'C' and card.cardnumber = 'ABC123456'


While a households attribute select would look like this:
Code:
select attdef.name, attval.value
from attributedetail attval
  inner join attributedefinition attdef on attval.attributeid = attdef.attributeid
  inner join household on attval.customerkey = household.id
where def.cphlevel = 'H' and household.State = 'OH'


What would you recommend the Model and/or hbm files look like? I'm kinda stumped.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 5:15 am 
Contributor
Contributor

Joined: Sun Jun 26, 2005 5:03 am
Posts: 51
Location: London, UK
Haven't tested this, but you could try the following...

Have three Attribute child classes, CardAttribute, PersonAttribute and HouseholdAttribute and set this up as table per hierarchy with the appropriate discriminator values. Don't have a reference on the Attribute class back to the owner however.

Now from the owning class, have a collection of the appropriate Attributes and then map it as follows for Card

Code:
<bag name="Attributes" lazy="true" where="cphlevel='C'">
  <key column="customerkey" />
  <one-to-many class="CardAttribute" />
</bag>

If your NHibernate app isn't going to insert Attributes, but only read them, then you don't need the Attribute child classes - they are there to hold the correct discriminator value on insert.

_________________
Paul Hatcher
NHibernate Team


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.