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