-->
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: Using @DiscriminatorColumn for Inheritance
PostPosted: Fri Dec 19, 2008 7:50 am 
Newbie

Joined: Fri Dec 19, 2008 7:29 am
Posts: 1
Location: London UK
Hi, I am wondering if anyone can help.

I have a set of classes Apple, Orange and Banana which all inherit from the Fruit class. I want to use the Single Table Strategy to persist all of the Fruit classes.

I understand I can use a @DiscriminatorColumn('FruitType') in the Fruit class and the @DiscriminatorValue('Apple'), @DiscriminatorValue('Orange') and @DiscriminatorValue('Banana') in the Apple, Orange and Banana classes, then make sure I have the FruitType column on the database set to either Apple, Orange or Banana.

What I would like to do if possible is have a FruitTypes table in the database to hold a list of valid @DiscriminatorValues, something like this:

Id Name
------------
1 Apple
2 Orange
3 Banana

Then I could set up FruitTypeId on the Fruit table as a foreign key to FruitTypes and instead of using 'Apple', 'Orange' or 'Banana' I could use 1, 2 or 3.

However I would still like to keep the meaningful @DiscriminatorValues in the Apple, Orange and Banana classes i.e. @DiscriminatorValue('Apple') instead of @DiscriminatorValue('1').

Is there a value for @DiscriminatorColumn that will achieve this? Something like:

@DiscriminatorColumn('SELECT FruitType.Name FROM FruitType, Fruit WHERE FruitType.Id = Fruit.FruitTypeId')


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.