-->
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.  [ 1 post ] 
Author Message
 Post subject: Multilevel inheritance with discriminators
PostPosted: Tue Apr 19, 2005 5:47 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
Hi,
I'm currently working on a mapping of a very complex data model.
The model uses inheritance very extensively. From the given relational model a table-per-subclass mapping is appropriate (there is already a table for each subclass, the model itsself is standardized - no changes are possible) Additionally there is a discriminator column in each table.

My first solution used the table-per-class-hierarchy mapping although it did not fit too well. I used it for the reason that this kind of mapping provides a simple solution for the discrimator column.

It works fine on the first level of inheritance:

class ObjItem {
...}

class Org extends ObjItem {
...}

If I now use a discriminator column for the mapping-file of ObjItem, like

<class
table="OBJ_ITEM"
name="ObjItem"
discriminator-value="OI"
>
<id>...</id>
<discriminator column="CAT_CODE">
...

</class>

and use it in the subclass Org:

<subclass
name="Org"
extends="ObjItem"
discriminator-value="OR"
>
<id>...</id>

<join table="ORG">
<key column=ORG_ID>
<!-- properties -->
....

</subclass>

... everything well so far.

But now with a third class Unit, that extends Org:

class Unit extends Org {
...}

has the following mapping (accordingly to Org):
<subclass
name="Unit"
extends="Org"
discriminator-value="UN"
>
<id>...</id>

<join table="UNIT">
<key column=UNIT_ID>
<!-- properties -->
....

</subclass>

But that is not what I want to do. I want Unit to use the discriminator column of Org. The same for other classes as well. Each inheriting class should use the discriminator column of the class that it directly inherits from. But it is not possible to define such a discriminator column in Org? Something like:

<subclass
name="Org"
extends="ObjItem"
discriminator-value="OR"
>
<id>...</id>

<join table="ORG">

<discriminator="CAT_CODE">

<key column=ORG_ID>
<!-- properties -->
....

</subclass>

I know that the <subclass> element is not meant to deal with several tables (as the name table-per-class-hierarchy implies), but is there another way to deal with this problem? Do ask whether my underlying model is useful or not - I have no choice. Actually it has some advantages (you can retrieve objects of every level of the inheritance just by selecting rows from one table through the discriminator and joining it with only one table).

Another approach of mine was using <joined-subclass> instead, but then I have to define the CAT_CODE as a fixed property. Is that possible? For example setting in the joined-subclass Org a property of the parent class (ObjItem) to a constant value ("OR") on each level?

Or can you advice another mapping stratety or work-around? (I prefer not setting the CAT_CODE property in the constructor of the Pojos.)

I would appreciate some help! Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.