aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "InheritanceType.JOINED  and DiscriminatorColumn" Watch "InheritanceType.JOINED  and DiscriminatorColumn" New topic
Author

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.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Inheritance#No_class_discriminator_column_2

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)
 
wood burning stoves
 
subject: InheritanceType.JOINED and DiscriminatorColumn
 
Similar Threads
Hibernate - Using subclass and joined-subclass element
Help with a Mapping
hibernate table per class hirearchy discriminator value with query
Using the discriminator column in QL queries and primary keys
Problem in Joined Inheritance Strategy, getting null value in parent Discriminator column