This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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