• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping Class Inheritance

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I was just reading the topic Mapping Class Inheritance from the book Java Persistence with Hibernate. I am not able to understand some of the points.

1. Table per concrete class with implicit polymorphism - It says that main problem with this approach is that it doesn't support polymorphic associations very well. Secondly, A query against superclass must be executed as several SQL selects. I didn't understand these statements.

2. Table per concrete class with Unions - Its says an association from User to BillingDetails would now be possible. Didn't understand this either.

Please explain me the concept behind these lines. Thanks in advance.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Siddharth Bhargava:
Hi All,
I was just reading the topic Mapping Class Inheritance from the book Java Persistence with Hibernate. I am not able to understand some of the points.

1. Table per concrete class with implicit polymorphism - It says that main problem with this approach is that it doesn't support polymorphic associations very well. Secondly, A query against superclass must be executed as several SQL selects. I didn't understand these statements.




The idea of Table per concrete class is that ALL of the attributes of the superclass are in each table for each concrete class. Thus if you want to find out something about all of the subclasses (e.g. a query against the superclass) then you must query each table individually because the tables have no relationships to each other.

I'll address the second question in another post.



2. Table per concrete class with Unions - Its says an association from User to BillingDetails would now be possible. Didn't understand this either.

Please explain me the concept behind these lines. Thanks in advance.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Look at the following, very simply class diagram:



With a TABLE_PER_CLASS mapping, notice how the properties in the parent get duplicated in each database table down the hierarchy.



With a Joined strategy, you don't run into this issue, as data is accessed through the union of the tables:



Of course, I always like just using one table. One big table that I can access with one line of code. Store it in the root of C:\, and life is grand:



These images are taken from a very simple tutorial on the topic on my website. Have a look if you like:

Understanding ORM Inheritance Mapping

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic