File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Join using Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Join using Hibernate" Watch "Join using Hibernate" New topic
Author

Join using Hibernate

Mahek Singhal
Greenhorn

Joined: Dec 09, 2004
Posts: 1
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...??


Mahek Singhal
Jan Vandernoot
Greenhorn

Joined: Mar 05, 2002
Posts: 6
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
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Join using Hibernate
 
Similar Threads
Hibernate 3.0
NullPointerException when run stand alone program
hibernate migration
JOIN syntax for HQL . Need help!
Hibernate composite-id