-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Need help with many-to-many query
PostPosted: Fri Mar 18, 2005 12:20 pm 
Newbie

Joined: Fri Mar 18, 2005 12:09 pm
Posts: 10
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0

Name and version of the database you are using:

Oracle 8.1.7

Question
Hi there. Apologies for asking a simple question in the forum, but I've tried RTFM'ing and searching the forum and I can't find an explanation to the very basic question below.

I have three tables representing a many to many relationship between an Employee and that employee's current roles in the application.

EMPLOYEE, EMPLOYEE_ROLE, ROLE

I believe I have all of my mapping files correctly set up [if not I can debug on my own]. However, I have no idea how to write a Hibernate query with a condition on the other side of a many to many relationship.

Logically, I want to query for all employees with a particular role

In SQL I would normally write would be something like:

SELECT EMPLOYEE.ID FROM EMPLOYEE E, EMPLOYEE_ROLE ER, ROLE R
WHERE
E.ID = ER.EMPLOYEEID
AND
ER.ROLEID = R.ID
WHERE R.NAME = "Administrator"

How do I do this in Hibernate?

[please feel free to just point me to the documentation or similar posts on the forum]

Thanks in advance,

-Tim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 2:01 pm 
Beginner
Beginner

Joined: Fri May 21, 2004 12:21 pm
Posts: 22
Location: Sacramento CA, USA
select Employee.id
from Employee as employee
join employee.employeeRoll as ER
join ER.Roll as roll
where r.Name ="Administrator"

The "." in the joins specify your SQL joins.
Read chapter 14 in reference manual for more details.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 18, 2005 3:09 pm 
Newbie

Joined: Fri Mar 18, 2005 12:09 pm
Posts: 10
Thanks perumal!

I'm glad it's so straightforward. Sorry for the simple (dumb?) question, and thanks for pointing me to the right resource. I'll go RTFM.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.