This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

newbie hibernate question regarding joins  RSS feed

 
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 !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!