-->
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: mixing inheritance strategies "the wrong way"
PostPosted: Thu Jul 07, 2005 3:06 am 
Beginner
Beginner

Joined: Tue Jun 28, 2005 2:43 pm
Posts: 29
Location: Silicon Valley
Using Hibernate3, have read the reference documentation, am most of the way through Hibernate in Action.

I want to use a mixed inheritance mapping strategy, using a combination of table-per-subclass (i.e. join-subclass) and table-per-hierarchy (i.e. subclass, with a discriminator). The problem is that, as I understand it, while the syntax allows me to switch from subclass to join-subclass, it doesn't let me switch the other direction. In other words, the 'superclass table' can contain rows representing instances of different classes, but each 'subclass table' joined to it contains rows representing only one class.

Consider:
Code:
<class name="Item" table="ITEM" discriminator-value="0">
  ... id, discriminator, properties, associations ...

  <subclass name="Source" discriminator-value="1">
    <join table="SOURCE">
    ...
    </join>
  </subclass>

  <subclass name="Document" discriminator-value="2">
    <join table="DOCUMENT">
    ...
    </join>
  </subclass>
</class>

Source and Document have very different data content, making a join-subclass approach desirable. But each has multiple subclasses that differ not so much in content as behavior--in other words, poster-child cases for using a table-per hierarchy strategy.

Attempt 1:
Code:
<class name="Item" table="ITEM" discriminator-value="0">
  ... id, discriminator, properties, associations ...

  <subclass name="Source" discriminator-value="1">
    <join table="SOURCE">
    ... key, properties, associations ...
    </join>

    <subclass name="Foo" discriminator-value="3">
    </subclass>

    <subclass name="Bar" discriminator-value="4">
    </subclass>

  </subclass>

  ...
</class>

This parses ok, and it maps the Source class to both ITEM and SOURCE. But Foo and Bar get mapped only to the ITEM table, not to ITEM and SOURCE as intended.

Attempt 2:
Code:
<class name="Item" table="ITEM" discriminator-value="0">
  ... id, discriminator, properties, associations ...

  <subclass name="Source" discriminator-value="1">
    <join table="SOURCE">
    ... key, properties, associations ...
    </join>
  </subclass>

  <subclass name="Foo" discriminator-value="3">
    <join table="SOURCE">
    ... same key, same properties, same associations ...
    </join>
  </subclass>

  <subclass name="Bar" discriminator-value="4">
    <join table="SOURCE">
    ... same key, same properties, same associations ...
    </join>
</subclass>

  ...
</class>

We might call this a mixed table-per-subclass + implicit polymorphism approach. This actually gives close to the desired behavior, in that Source, Foo, and Bar are all mapped to both the ITEM and SOURCE tables. The main indication that it's not quite right is that in the generated DDL, it puts the same foreign key constraint on SOURCE three times. Plus, it doesn't "feel" right to declare Foo and Bar as direct subclasses of Item when they are really subclasses of Source.

So, is this an abomination? is there a better way to do it? All thoughts appreciated. Thanks.


Top
 Profile  
 
 Post subject: Did you get a response?
PostPosted: Tue Jan 03, 2006 9:00 am 
Newbie

Joined: Tue Apr 27, 2004 4:31 am
Posts: 13
Hello Frusso,

I cannot believe that the suggestion you made still is not possible using Hibernate. Did you already receive an answer? And maybe a working example?

What we would like to do is:

Code:
[b]<class>
  <joined-subclass>
    <discriminator/>
    <subclass>

    </subclass>
  </joined-subclass>
</class>[/b]


Greetz,
E.W. Snatcher


Top
 Profile  
 
 Post subject: Re: Did you get a response?
PostPosted: Tue Jan 03, 2006 9:15 am 
Newbie

Joined: Thu Mar 17, 2005 7:06 am
Posts: 4
ewsnatcher wrote:
What we would like to do is:

Code:
[b]<class>
  <joined-subclass>
    <discriminator/>
    <subclass>

    </subclass>
  </joined-subclass>
</class>[/b]



Maybe you can use this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 03, 2006 9:17 am 
Newbie

Joined: Tue Apr 27, 2004 4:31 am
Posts: 13
Needless to say: That is the other way around.

E.W. Snatcher


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.