This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes InheritanceType.JOINED  and DiscriminatorColumn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "InheritanceType.JOINED  and DiscriminatorColumn" Watch "InheritanceType.JOINED  and DiscriminatorColumn" New topic

InheritanceType.JOINED and DiscriminatorColumn

Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

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.
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
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.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188

Hi James ,

That answered my question perfectly, the site you mentioned is awesome too !
Krum Bakalsky
Ranch Hand

Joined: Mar 14, 2010
Posts: 46
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....

SCJP 6 (86% - the hard way), SCBCD 5 (81% - the hard way)
I agree. Here's the link:
subject: InheritanceType.JOINED and DiscriminatorColumn
It's not a secret anymore!