-->
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.  [ 2 posts ] 
Author Message
 Post subject: What is the most effective way to do a many-to-many query?
PostPosted: Mon May 22, 2006 3:51 am 
Newbie

Joined: Fri Feb 17, 2006 12:18 am
Posts: 11
hi, I want to know what is the most effective way to execute a many-to-many query?

for example, Student, Course and Student_Course entities, how to select courses belong to specified student?

I know "select course in (select ...)" but it may not the effictive way.

thx!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 22, 2006 6:16 am 
Newbie

Joined: Wed Dec 21, 2005 6:41 am
Posts: 2
In plain SQL:

Code:
select  c.*
  from Course c, Student_Course sc, Student s
  where c.id = sc.course_id
    and sc.student_id = s.id
    and s.id = :id


The HQL would probably be (depending on your mappings):

Code:
select c
  from Course c
  join c.students s
  where s.id = .id


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.