• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Join using Hibernate

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I m trying to join two tables say hiber_employee(id,empId,name,designation) and hiber_company(companyid,empid,grade,salary).
but i dont want to store the joined values into a new table.
i have made three persistence classes for each table and 1 POJO for the join.
my hiber_join.hbm.xml file looks like..

<hibernate-mapping >
<class name="join.Hiber_Join" >
<id name="joinId" type="int" unsaved-value="null">
<column name="ID" sql-type="number" not-null="true"/>
<generator class="hilo"/>
</id>
<property name="empId"/>
<property name="name"/>
<property name="grade"/>
<property name="salary"/>
<property name="designation"/>
</class>
<class name="join.Hiber_Company" table="hiber_company">
<id name="companyId" type="int" unsaved-value="null">
<column name="COMPANY_ID" sql-type="number" not-null="true"/>
<generator class="hilo"/>
</id>
<property name="empId"/>
<property name="grade"/>
<property name="salary"/>
</class>
<class name="join.Hiber_Employee" table="hiber_employee">
<id name="id" type="int" unsaved-value="null">
<column name="ID" sql-type="number" not-null="true"/>
<generator class="hilo"/>
</id>
<property name="name"/>
<property name="empId"/>
<property name="desgn"/>
</class>
</hibernate-mapping>

is this the right way of writing .hbm.xml in case of join...??
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

You don't do joins in Hibernate, Hibernate does it for you. You should read the Hibernate reference manual (http://www.hibernate.org/hib_docs/v3/reference/en/html/), it explains everything you need to know...

Regards,
Jan
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're trying to design your classes around the database. What you should be doing is design the classes then map them to the database. It looks to me like you should only have two classes, somthing like:

From there you could build your Company.hbm.xml and Employee.hbm.xml
 
You get good luck from rubbing the belly of a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic