-->
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.  [ 7 posts ] 
Author Message
 Post subject: Mixing Polymorphism Strategies
PostPosted: Tue Apr 13, 2004 1:34 am 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
I have the following class hierarchy.

"User", "Administrator", and "Representative" are all subclasses of "UserEntity". Since the 2 of these 3 subclasses have a reasonable number of properties that are unique to them, I declare these in hibernate using joined subclasses. No problem here.

Now though, I want to subclass "User" a bit more, but for these 2 sub-subclasses, I want to use a discriminator.

Doing this looks fairly straightforward, but I can't get XDoclet to generate me a proper looking UserEntity.hbm.xml when it comes to the subclasses of User. In fact, I'm not even seeing the subclass tags get generated.

Can I do this? If so, how do these particular XDoclet tags work?

TIA

-Joe

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 4:03 am 
Newbie

Joined: Mon Sep 20, 2004 1:57 am
Posts: 3
Sorry for bumping an old thread, but I've been looking for an answer to a very similar question, to no avail.

OK, I realize that <subclass> and <joined-subclass> don't mix. Which is probably what the answer to the original question would be. So the real question here is - what can be done in order to "spoof" a mixed hierarchy of this sort?

I am working on a largish project, which, like the original poster, uses a persistent base class (i.e., the base class has specific fields that must be persisted and must be accessible via casting to the base type). Under this class, I have quite a diverse number of derived classes, which lend themselves fairly naturally to a table-per-subclass strategy. However, many of these derived classes have, in turn, derived children of their own, which really should be persisted within the same table as the second-tier objects.
Since I can't mix table-per-hierarchy and table-per-class startegies, and I also can't change the Object Model to split the hierarchy into smaller sub-hierarchies which could be persisted as table-per-hierarchy in a natural way (I have to keep the base class and keep it concrete and persistable), what can anyone suggest as a possible strategy? Is there any difference between what can and cannot be accomplished by using XDoclet tags and by writing *.hbm.xml files manually?

Again, sorry for what may be a newbie question (and for the bump), but I've gone this far back in the forum archives without finding an answer, so here goes...

Regards,

Dani


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 7:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
In Hibernate3, you can hack around with the <join> element a little.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 8:27 am 
Newbie

Joined: Mon Sep 20, 2004 1:57 am
Posts: 3
michael wrote:
In Hibernate3, you can hack around with the <join> element a little.

In other words, the answer to my question is "you can't do this!"? Or is there some way of mixing and matching strategies in Hibernate 2.x which I am unaware of?

I can't migrate to Hibernate 3 quite yet, as we are creating a shippable product and I don't want to use Alpha software in it - as good as it may be.

Thanks

Dani


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 20, 2004 8:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
For Hibernate 2 it is "you cant mix inheritance strategies"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 7:09 am 
Newbie

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

I am looking forward to the solution in Hibernate 3.
I hope its use will be straightforward, like a discriminator being available from within a joined-subclass element, like:

Code:
<joined-subclass
  extends="com.foo.QuestionComponent"
  name="AbstractQuestion"
  table="AbstractQuestion"
  lazy="false"
  dynamic-update="true"
  dynamic-insert="true"
  proxy="IAbstractQuestion"
>
  <discriminator
    column="questionType"
    type="string"
  />

  ...



Greetz,
Erwin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 7:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Code:
<hibernate-mapping package="com.eyrolles.sportTracker.model">
  <class name="Person" table="PERSON">
    <id name="id" column="PERSON_ID">
      <generator class="native"/>
    </id>
    <discriminator column="PERSON_TYPE" type="string"/>
    <subclass name="Player" discriminator-value="PLAYER">
      <join table="PLAYER">
        <key column="PLAYER_ID"/>
      </join>
...
    </subclass>
    <subclass name="Coach" discriminator-value="COACH">
      <join table="COACH">
        <key column="COACH_ID"/>
...
      </join>
    </subclass>
  </class>
</hibernate-mapping>


we are studying another solution but for the moment this is what you should do for table per subclass + discriminator

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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