wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Mapping Class Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping Class Inheritance " Watch "Mapping Class Inheritance " New topic
Author

Mapping Class Inheritance

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 268
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

Joined: Aug 10, 2001
Posts: 3892
    
    5
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.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mapping Class Inheritance