This week's book giveaway is in the Java in General forum.
We're giving away four copies of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 and have ishori Sharan & Adam L Davis on-line!
See this thread for details.
Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

hybernate doubt

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

thanks,
Sudha.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Place as many classes as you want inside the hibernate mapping file as follows,
<hibernate-mapping>
<class name="event.Employee" table="employee">
<id name="id" >
<generator class="increment"></generator>
</id>
<property name="empId" column="EMP_ID"/>
<property name="empName" column="EMP_NAME"/>
<property name="empPwd" column="EMP_PASSWORD"/>
</class>
<class name="event.Employee" table="dept">
<id name="id" >
<generator class="increment"></generator>
</id>
<property name="empId" column="EMP_ID"/>
</class>
</hibernate-mapping>
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
Ramana
 
Ranch Hand
Posts: 1374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thirumurugan,

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.

sudha,

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic