-->
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: Sub-discriminators?
PostPosted: Thu Feb 09, 2006 11:36 am 
Newbie

Joined: Wed Feb 08, 2006 6:29 pm
Posts: 1
In a finance application, I have a single table called ProductDetails. From this table, I need to first determine a subclass based on a field in the database ( i.e. productType, which can be like BOND or OPTION ). I've set up a discriminator to do this, and it works quite well. I have a ProductAbstract class, and then ProductBond and ProductOption classes which extend it. Works like a charm.

However, for BOND products, I need to further be able to subclass the data based on a different column in the ProductDetails table. For simplicity say we have a bondType field, which can be either CORPORATE, MUNI, or GOVERNMENT. I can't base my first discriminator on this column, because it's only populated for BOND types (not the best data model, but we're stuck with it at this point).

I thought I'd just be able to set up another discriminator at the ProductBond subclass level, but they can't be defined at the subclass level.

Basically, I need to set up a discriminator based on two fields. I've thought of concatenating the two fields into a new database column and basing my discriminator on the new column, but think that's a bit ugly.

I've done some digging, and have seen that I might be able to do this using a <formula> tag, or an EnhancedUserType. I've not been able to find any examples on setting these up. Could someone please get me pointed in the right direction? Alternative approaches and/or example code would of course be very appreciated. Thanks very much.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 5:49 pm 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
I've had a similar situation where I also needed sub-discriminators. However I was able to get the discriminator formula working. Here's an example of the formula:

case when column1='Val' and column2='A' then 'SubType-A'
when column1='Val' and column2='B' then 'SubType-B'
when column1='Val' and column2='C' then 'SubType-C'
when column1='Val' and column2='D' then 'SubType-D'
when column1='Val' and column2='E' then 'SubType-E'
else column1 end

In this example the column1 is intended to be the mainDiscriminator, and the column2 is the sub-discriminator.

So in each of your objects, you'll set up the discriminator value mapping as SubType-* or any other value found in column1.

There is one drawback to this approach. When I create a new object, the discriminator column won't be automatically populated, as it would if you didn't use a formula. Therefore, in each subclass, you must "force" the value of column1 (and column2 in some cases). We did this in the default constructor by using abstract methods we defined.

In the end, it wasn't the most straightfoward approach, but it was easier and more natural to treat these objects as a hierarchy.

_________________
-Chris


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.