-->
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.  [ 4 posts ] 
Author Message
 Post subject: hql many-to-many fetching
PostPosted: Tue Aug 17, 2004 8:39 am 
Newbie

Joined: Tue Aug 17, 2004 8:19 am
Posts: 8
Location: Paris
Hi,
I'm trying to figure out how to implement something in HQL

I have 3 tables:

Code:
PROJECT(ID, DESCRIPTION)
PROJECT_USER(PROJECT, USER)
USER(ID, USERNAME, FIRST_NAME, LAST_NAME)


Where the PROJECT_USER table is the relationship table for a many-to-many mapping as a set between PROJECT and USER:

In my project hbm file
Code:
   

        <set name="users" table="project_user">
          <key column="project">
            <column name="id" not-null="true"/>
          </key>
          <many-to-many class="net.bookingasp.data.core.user.pojo.User">
            <column name="user" not-null="true"/>
          </many-to-many>
        </set>

I want to get all PROJECTs (as pojos) associated with a particular USER.
In SQL, I'd do something like the following:

Code:
SELECT P.ID, P.DESCRIPTION
  FROM PROJECT P,
       PROJECT_USER PU,
       USER U
WHERE P.ID = PU.PROJECT
   AND PU.USER = U.ID
   AND U.USERNAME = 'CLINTONB';


But how do i do this with hql??? I'm completely lost...
It must be simple, right?

Many thanks in advance,
Birju


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 2:39 pm 
Newbie

Joined: Tue Aug 17, 2004 8:19 am
Posts: 8
Location: Paris
i've figured it out, cheers.
it was very simple indeed!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi,
Quote:
i've figured it out, cheers.

give the solution of your pb, it might help other users who read your topic

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 4:55 am 
Newbie

Joined: Tue Aug 17, 2004 8:19 am
Posts: 8
Location: Paris
Sure....

It was a 'join' with alias (bypassing the many-to-many table)
Code:
select p
  from net.bookingasp.data.workflow.process.pojo.Project p
  join p.users u
where u.login = :login

Birju


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