• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Hibernate @DiscriminatorColumn

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have four classes that map to four tables

ClassType, MainClass, SubClassOne, SubClassTwo

ClassType maps to the table "Class_Type" and consists of two attributes
1) Class_Type_Cd C(4) Not Null PK
2) Class_Type_Desc VC(40) Not Null

MainClass maps to the table "Main_Class" and consists of three attributes
1) Main_Class_ID Integer Not Null Auto_Generated PK
2) Class_Type_Cd (FK from Class_Type)
3) Main_Class_Name VC(40) Not Null

SubClassOne maps into the table "Sub_Class_One" and consists of two attributes
1) Sub_Class_One_ID Integer PK (Dependent upon Main_Class_ID)
1) Int_Value Integer Not Null

SubClassTwo is the same as SubClassOne, with a String_Value (as opposed to an Int_Value)


I would like to join the MainClass with either SubClassOne or SubClassTwo, based upon the value of the ClassTypeCd (fk into the MainClass)

I am using annotations, and cannot for the life of me figure out how to use the key value as opposed to a set string value, I would like to be able to set the below...

@DiscriminatorColumn(name="???", discriminatorType=DiscriminatorType.STRING)

where "??? is the value of this.getClassType().getClassTypeCd()

that way I can use the ClassType Description to get at the subclass from the MainClass

Does anyone have an example of how to do this?

Thanks, in advance, Thomas

PS - this is not a homework question, I'm trying to come up with a template to effectively add subtype tables to a schema without going into my main (superclass/supertype) constructs
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The discriminator column is meant to be used in the "single table per class hierarchy" mapping. Doesn't apply here...
 
Tom Bigbee
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, however, that still does not answer my question

The book - Java Persistence with Hibernate lists four types of inheritance Paradigms

#4 Table per subclass�Represent is a (inheritance) relationships as has a (foreign key) relationships.

Some database systems (Oracle, for example) limit the number of
tables in an outer join operation. For a wide hierarchy, you may want to switch to a different fetching strategy that executes an immediate second select instead of an outer join:


I'm wondering if anybody has an example of this with annotations
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the sample, the thing is called "discriminator-value", and there is, in JPA at least, a @DiscriminatorValue annotation. Maybe this is what you are looking for...
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic