This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • 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 !
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!