• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Join using Hibernate

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic