Advertisement :
   Log In    OR    Register  
  Topics :  
RMI Example

Home >>> Hibernate Tutorial >>> mapping class hierarchy table per subclass >>> Example
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : Amit
Title :
Interview Questions
Description : On Hibernate
More...


Written By : Amit
Title :
mapping class hierarchy table per subclass
Description : Example
More...


Written By : Amit
Title :
ways create Hibernate SessionFactory
Description : Example
More...


Written By : Amit
Title :
Spring Hibernate Integration example
Description : Example
More...


Written By : Amit
Title :
ORM Hibernate Best FIT
Description : Discussion
More...


Written By : Amit
Title :
One to Many mapping example
Description : Code
More...

Tags/Keywords : Example - mapping-class-hierarchy-table-per-subclass - Hibernate-Tutorial Example
Author : Amit
Date (Year/Month/Date): 2009-02-17 Mapping class Hierarchy to Table
Books/References  :

Hibernate mapping for object
hierarchy using table per
subclass way:
1. Persisting Parent child
relationship (Inheritence in
domain objects) in RDBMS ,
using Hibernate as ORM tool.
This aspect of mapping object
hierarchy is better understood
when I sat down in front of my
Laptop and started implementing
a case study of my own.

 Suppose, a person has a profile
 that contains his name, age,
 contact information etc.
 Contact can have phone, email,
 address, and Address constitutes
 of address line one, line two,
 line three, city, state, pin
 code etc. In this case, the
 domain classes, I can think
 of are Person Contact and
 Address class.
Advertisement :
Suppose, a person has a profile that contains his name, age, contact information etc. Contact can have phone, email, address, and Address constitutes of address line one, line two, line three, city, state, pin code etc. In this case, the domain classes, I can think of are Person Contact and Address class. Person Contact Address ------- ------- ------- personId contactId addressId name emailId addrLine1 age phoneNumber addrLine2 addrLine3 city state pin In order to persist this object hierarchy, There are three possible ways (please refer http://www.hibernate.org for details), 1. Table per concrete class 2. Table per hierarchy 3. Table per subclass In this example I am going to use table per subclass. I think this type of mapping for object hierarchy is having better database normalization, as it has different tables for each domain class, like in this case, there are three tables for three domain classes , such as Person, Contact and Address and unlike 'table per hierarchy' where the entire object hirarchy is persisted in a single table, and can have duplicate records for different object states with a slight change in combination of field values for different sub classes/objects. Person class that is the parent class here in this example, has class tag, and Contact should be included inside Person as joined-subclass, and Contact joined-subclass has another joined-subclass for Address. So there are three tables as Person, Contact and Address, with the person_id as primary key in Person table, contact_id as primary key/foreign key to person_id in Person table. Similarly address_id is primary key /foreign key to contact_id in Contact table. One important point to be noted here is that all the three ids (person_id, contact_id and address_id) are same and one value only. As there is no Agregation or composition exist among these objects. The complete object hierarchy is identified by a single instance or key only, as multiple inheritance of classes is not possible in Java Technology. It is quite logical to assume that all the primary keys such as person_id, contact_id, and address_id should have same value. The client code is like the following, where the Address object can be used to store all the fields values of its super classes, Contact and Person: Address address = new Address(); address.setPersonId("P003"); address.setName("Girish"); address.setAge(23); address.setPassportNumber("PPP"); address.setContactId("P003"); address.setPhoneNumber(234323); address.setEmailId("share.understanding@gmail.com"); address.setAddressId("P003"); address.setAddrLine1("123 street"); address.setAddrLine2("Street Marg"); address.setAddrLine3("Fun"); address.setCity("Pune"); address.setState("Maharashtra");
Author of this article/writeup has expressed his/her willingness
to help or guide users with any technical difficulties he/she faces while working with the example code environment setting up, running and resolving any such exception raised during compile or at runtime. You may ask for any technical doubt or seek technical help related to this article by using following form to reach for technical help from the Author for FREE. This article's Author shall be reading your request and responding within reasonable time (no resolution timeframe defined as such).


	

Commented By ->
Girish
Can you provide related mapping HBM file with appropriate example
for 1. Table per Hierarchy
2. Table per concrete class ???

Commented By ->
Girish
What are the basic difference between Hibernate component mapping 
and Hibernate Association mapping?
Please show me some example on this.
Are you interested in solving a very interesting Technology Stack while Playing this Game          

Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
22,28
Enter bigger number from above :*
Home >>> Hibernate Tutorial >>> mapping class hierarchy table per subclass >>> Example
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
40,12
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER
Terms of Use and Disclaimer :

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed materials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.

By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or 
downloading any materials, you agree to and are bound by the terms of use 
described in this page and Usage Terms and Conditions. 
If you do not agree to all of 
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this 
website in any manner. If you are using the website on behalf of your 
employer, you represent that you are authorized to accept these Terms of Use 
on your employer's behalf.

All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any 
of these information, please refer original content/documentation from respective sources. 
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.