| Author |
Hibernate : Hibernate :Mapping Multiple Table for single POJO class
|
sachin Misurkar
Greenhorn
Joined: Jul 24, 2008
Posts: 5
|
|
Hi All, I have requirement to map Different Table to one POJO class. Example; Table 1)Employee: -EmpName -EmpAddress -EmpPhone 2)HealthDetails : - Height - Weight - BloodGroup I want create single POJO class which contains fields from Both table. Pleasez suggest me How to do hibernate mapping(Mapping *.hbm.xml file) for such scenario.... Thanks in Advance regards sachin misurkar
|
 |
Rodrigo Lopes
Ranch Hand
Joined: Feb 29, 2008
Posts: 118
|
|
Take a look at this You must have something like:
|
 |
sachin Misurkar
Greenhorn
Joined: Jul 24, 2008
Posts: 5
|
|
Thank You Rodrigo I also got solution.....
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
It's just as easy with annotations: Mapping One Class to Two Tables: The Secondary Table!
One Class to Two Tables From time to time, you'll run into a scenario where your application defines a single class, but the database maintains the correspoinding information in two separate tables. Well, with Hibernate, that's not a problem. All you have to do to map one class to two database tables is to define the first table mapping as you normally would, and then specify the name of the second table your class uses with the very intelligently named @SecondaryTable annotation. From there, when you get to a field that is supposed to be stored in the second table, well, you just mention the second table's name in the @Column annotation. It's all very simple and straight forward.
Here's a little scenario I map in a tutorial of mine. You'll notice that the code is pretty clean.  Mapping Tutorial So there you go! It's as easy as using the SecondaryTable annotation! -Cameron McKenzie
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
Sandeep Vaid
Ranch Hand
Joined: Feb 27, 2006
Posts: 390
|
|
What if these 2 tables doesn't have same composite keys...
In this situation how can i map one class to these 2 tables ?
|
 |
 |
|
|
subject: Hibernate : Hibernate :Mapping Multiple Table for single POJO class
|
|
|