-->
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.  [ 1 post ] 
Author Message
 Post subject: Self Reference Sub Queries
PostPosted: Mon Oct 08, 2012 6:51 am 
Newbie

Joined: Mon Oct 08, 2012 6:39 am
Posts: 1
Hi All,

I have created self reference many to many relationship using grails, here's my domain:
Code:
class User {
    String username
    String password
    String fullname

    static hasMany=[friends:User]
    static mappedBy  = [ friends: 'friends' ]
}


which generate two MySQL tables:
Table user:
id bigint primary key
version bigint
username varchar(255)
password varchar(255)
fullname varchar(255)

Table user_friends:
user_id bigint
friends__id bigint

I have done MySQL query successfully to get friends data of a user where its friends of user friends that not current user and current user friends.
Code:
select fullname from user where id in (select friends__id from user_friends where user_id in(select friends__id from user_friends where user_id=16)) and id<>16 and id not in (select friends__id from user_friends where user_id=16)


user_id=16 is current user

My question is how I do it with HQL?


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

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.