Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InheritanceType.JOINED and DiscriminatorColumn

 
Sudarshan Sreenivasan
Ranch Hand
Posts: 188
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • 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 Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James ,

That answered my question perfectly, the site you mentioned is awesome too !
 
Krum Bakalsky
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • 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....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic