• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie hibernate question regarding joins

 
Ben Hsu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a simple question, I have two tables in a one-to-many relationship and I want to join them in an HQL query. How do I do that?

Lets say I have the classic example of a "departments" table and an "employees" table. I have this bit of XML in my employees.hbm.xml file:

<set name="employees" table="tblEmployee">
<key column="dept_id"/>
<one-to-many class="example.Employee"/>
</set>

I have the "Set employees" in my Employees.java bean, along with the getters and setters.

I've tried "from Department.employees" and "from Department join Employees", neither worked. The first said that Department.employees could not be mapped, the second said that it needed a "dotobject" in the join.

This looks very basic. I tried looking for examples but failed. Any help would be appreciated. Thanks so much!
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i can give you an example from one of our project


here it is an outer join

a sg id SteeringGroup that contains several SubGroup that is linked to a dg that have a proprerty id !


hope it helps !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic