-->
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: Best approach to handle this many to many relationship
PostPosted: Mon May 14, 2007 1:05 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
Hi,

Want to implement a feature to allow a user to block a list of other users. The use case is for any given user id, find the list of users he blocks.

I use a many-to-many relationship table to map the relationship:
user1_id, user2_id

Since there might be a huge long list of users a user want to block, I don't want to keep a list of blockedUsers inside my user data object. May even need to implement pagination to show the list of blocked users.

What's the best way I can use Hibernate to maintain the relationship and answer query like: findBlockedUserListByUserId(userId).

Should I use native SQL with addEntity? Is there a better way?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 11:27 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
Any idea? It should be a common problem. If the same question has been asked, a pointer to that thread would also help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 12:43 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
if the case is like this.... one admin user can block n number of users and one user can be blocked by many admin users..
then the relation can be defined in following way...

User_table
*User_id
User_Name

Admin_Table
*admin_id
*user_id

both of the above id refer to user_id in user_table...


this will be a bi-diectional one-to-many relation.

ur findBlockedUserListByUserId(userId) will fire a query on user_table and probably return list of user_id's

_________________
Hope this helps... :)

Regards,

Rohit

--Don'f forget to rate...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:31 am 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
Thanks. Don't think it is the answer I am looking for. It is not about Admin user. Any user can block any user (from sending message to them and ...).

Again, I don't want to keep a list of blockedUsers in my user data object. What's the best way to map the relationship and build a query like findBlockedUsersByUserId() using hibernate?

I can only think about using native query.

Sagi wrote:
if the case is like this.... one admin user can block n number of users and one user can be blocked by many admin users..
then the relation can be defined in following way...

User_table
*User_id
User_Name

Admin_Table
*admin_id
*user_id

both of the above id refer to user_id in user_table...


this will be a bi-diectional one-to-many relation.

ur findBlockedUserListByUserId(userId) will fire a query on user_table and probably return list of user_id's


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.