Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / January 2004

Tip: Looking for answers? Try searching our database.

CMP: Problems with many-to-many relation

Thread view: 
Eric Ford - 22 Jan 2004 10:59 GMT
We've been troubling for some time now with implementing a many-to-many
relation using CMP. We are using JBoss 3.0.8, Eclipse and XDoclet.

So, we have the following two tables:

User 1 -------- * Friend * ---------- 1 User

A User can have many Friends, and a Friend is also a user. Our main
objective is this: We are looking to find all Friends that belong to a
certain User. For each of these Friends, we need to be able to trace back to
User, so as we can retrive the User data for this Friend.
The two beans corresponding to these tables are UserBean and FriendBean.

We've set up the following in UserBean (excerpt):

* @ejb.interface-method

* @ejb.relation name = "ChatUser-Friend"

* role-name = "ChatUser-can-have-many-friends"

* target-ejb = "Friend"

*/

public abstract Collection getFriends();

/**

* @ejb.interface-method

*/

public abstract void setFriends(Collection friends);
Eric Ford - 22 Jan 2004 11:16 GMT
COMPLETE MESSAGE (Previous message was incomplete)

We've been troubling for some time now with implementing a many-to-many
relation using CMP. We are using JBoss 3.0.8, Eclipse and XDoclet.

So, we have the following two tables:

User 1 -------- * Friend * ---------- 1 User

A User can have many Friends, and a Friend is also a user. Our main
objective is this: We are looking to find all Friends that belong to a
certain User. For each of these Friends, we need to be able to trace back to
User, so as we can retrive the User data for this Friend.
The two beans corresponding to these tables are UserBean and FriendBean.

We've set up the following in UserBean (excerpt):

* @ejb.interface-method
* @ejb.relation name = "ChatUser-Friend"
* role-name = "ChatUser-can-have-many-friends"
* target-ejb = "Friend"
*/

public abstract Collection getFriends();
/**
* @ejb.interface-method
*/
public abstract void setFriends(Collection friends);

/**
 * @ejb.interface-method
 * @ejb.relation name = "Friend-ChatUser"
 *               role-name = "ChatUser-can-be-in-many-FriendList"
 *     target-ejb = "Friend"
 */
public abstract Collection getOccurencesInFriendList();

/**
 * @ejb.interface-method
 */
public abstract void setOccurencesInFriendList(Collection friends);

We've been able to generate the database correctly, and we're able to insert
data into the Friend table. We've also been able to get a list (Collection)
of FriendLocal-objects for a given user. However, what we are looking for,
is a list containing UserLocal-objects which the FriendLocal-objetcs refer
to.

Our approach so far, has been trying to implement a finder-method, but we
can't get it to work. When trying to deploy, we get a message saying that
JBoss can't find the field frienduser, even though we've got a method
Collection getFriendUser() in the FriendBean.

* @ejb.finder  signature = "Collection findByUsersFriends(
java.lang.Integer userid ) "
*     query = "SELECT OBJECT(f.frienduser) FROM ChatUser a, IN (a.friends)
AS f WHERE a.id = ?1 "
*     result-type-mapping = "Local"

Any suggestions, we'd really appreciate it!

Eric & Eirik
Michael Meyer - 29 Jan 2004 13:35 GMT
hi,

I would say that you should have only one Bean (user) because a friend is
also a user. I have never tried this but in my eyes you should have a
relationship to the same bean @ejb.target-bean user.

Michael

> COMPLETE MESSAGE (Previous message was incomplete)
>
[quoted text clipped - 58 lines]
>
> Eric & Eirik


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.