-->
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: HQL join, on users who haven't preformed an action
PostPosted: Wed Dec 15, 2010 11:41 am 
Newbie

Joined: Mon Feb 16, 2009 2:27 pm
Posts: 7
I'm looking to display users friends who haven't preformed certain actions. E.g borrowed a book, bought a book.

When a user buys/reserves to the book a row is recorded, So i need a hql query where it finds the friends of a user that excludes friends that have bought/reserved a book

There are no associations with these tables.

Code:
class UserFriend

  User user
  User friend
  int status // "accepted, pending, requested"


Code:
class BooksBought

  Book book
  User user
  int status // "reserved, bought"


The following two attempts don't really work, duplicates are picked up after entries are recorded in the BooksBought table.


Code:
UserFriend.exectueQuery("SELECT uf.friend FROM UserFriend uf, BooksBought bb WHERE uf.user =:user AND uf.status =:accepted AND bb.book =:book AND bb.user != uf.friend", [accepted:1, book:book, user:user])


user2_.data...............
from
user_friend userfriend0_
inner join
user user2_
on userfriend0_.friend_id=user2_.id,
books_bought books_bought1_
where
userfriend0_.user_id=?
and userfriend0_.status=?
books_bought1_.book_id=?
and eventrsvp1_.user_id<>userfriend0_.friend_id

Using "not exists" with the resulting sql,

Code:
UserFriend.exectueQuery("SELECT uf.friend FROM UserFriend uf, BooksBought bb WHERE  uf.user =:user AND uf.status =:accepted AND not exists (from bb where bb.book =:book AND bb.user = uf.friend)", [accepted:1, book:book, user:user])


user2_.data...............
from
user_friend userfriend0_
inner join
user user2_
on userfriend0_.friend_id=user2_.id,
books_bought books_bought1_
where
userfriend0_.user_id=?
and userfriend0_.status=?
and not (exists (select
books_bought1_.id
from
books_bought books_bought1_
where
books_bought1_.book_id=?
and books_bought1_.user_id=userfriend0_.friend_id))

They don't work and just stop working when entries are recorded, any ideas?


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.