-->
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: subclass/discriminator in a separate table?
PostPosted: Tue May 22, 2007 10:08 am 
Regular
Regular

Joined: Thu Nov 30, 2006 10:48 am
Posts: 59
If I have a simple object hierarchy e.g.
Person
Student : Person
Professor : Person
Dean : Person
that I want to persist using a single Person table, I know that if I keep the discriminator as a string in the Person table, it's straigtforward (discriminator-value="professor", discriminator-value="student", discriminator-value="dean"). But if I want to put the discriminator value into a different table w/ the Person table pointing to it, is this possible?
e.g.
Person table
column = ID (Primary Key, integer, Identity)
column = PersonTypeID (integer, foreign key to PersonType.ID)

PersonType table
column = ID (Primary Key, integer, Identity)
column = TypeName (string, this has the actual type name)

Thanks,
Bill

_________________
metazone


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 11:28 am 
Newbie

Joined: Mon Jun 04, 2007 12:26 pm
Posts: 13
Location: Houston, Texas
Use a formula in your discriminator definition in your Person class definition instead of a column mapping:

<discriminator
formula="(select t.TypeName from PersonType t
where t.ID = PersonTypeId)"
type="String"
/>

Then in your subclass definition you can use your string:

<subclass name="Student"
discriminator-value="student">
</subclass>

Hope that helps.


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.