jQuery in Action, 3rd edition
The moose likes Object Relational Mapping and the fly likes hybernate doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hybernate doubt" Watch "hybernate doubt" New topic

hybernate doubt

sudha javvadi
Ranch Hand

Joined: Mar 23, 2007
Posts: 97
Hi all,

How to map a class with more than one table?If the data is in multiple tables then how to map those tables with a single class?

Thirumurugan Sivaji

Joined: Mar 03, 2009
Posts: 20

Place as many classes as you want inside the hibernate mapping file as follows,
<class name="event.Employee" table="employee">
<id name="id" >
<generator class="increment"></generator>
<property name="empId" column="EMP_ID"/>
<property name="empName" column="EMP_NAME"/>
<property name="empPwd" column="EMP_PASSWORD"/>
<class name="event.Employee" table="dept">
<id name="id" >
<generator class="increment"></generator>
<property name="empId" column="EMP_ID"/>

Warm Regards,

Thirumurugan Sivaji

gopal ramana

Joined: Feb 04, 2009
Posts: 2
Hi ,

Using the <join> element, it is possible to map properties of one class to several tables.

please refer Hibernate_reference.pdf 3.2 , page no:78

Warm Regards,
Vikas Kapoor
Ranch Hand

Joined: Aug 16, 2007
Posts: 1374

Please keep below points while replying.
Read The Question.
Use Code Tags.

It is not at all good practice to have more than one mapping into your mapping files. So each mapping file should contain only one class mapping.


you can create two mapping files(*.hbm.xml) and put class mapping with same class name and different table name.
If you find any difficulties, you can always come back. Please show us some efforts.
I agree. Here's the link: http://aspose.com/file-tools
subject: hybernate doubt
It's not a secret anymore!