• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

InheritanceType.JOINED and DiscriminatorColumn

 
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am new to ORM and this may sound a silly question however please bare with me, I am quoting this from the API.


Is used to define the discriminator column for the SINGLE_TABLE and JOINED inheritance mapping strategies.




From what I gather JOINED will create a new table for each subclass, then why would we ever need to specify a Discriminator ?

Any thoughts ?

Thanks in advance.

 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is somewhat of a fuzzy area in JPA. The spec seems to require a discriminator, some JPA providers require the discriminator, and some don't.

In general it is better to have the discriminator, as it is easier to determine the class for each row by checking the discriminator, instead of having to null check each subclass' table's join columns.

Having a discriminator also makes querying much easier, for example query all instances of two or more subclasses. It also allows for inheritance to be mixed, i.e. some subclasses use joined and some share their parent's table.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Inheritance#No_class_discriminator_column_2
 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James ,

That answered my question perfectly, the site you mentioned is awesome too !
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Some vendors offer implementations of joined inheritance without the use of a discriminator column.
Discriminator columns should be used if portability is required.




From "Pro EJB 3: Java Persistence API" book....
 
There's a city wid manhunt for this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic