One approach is to use a relationship table to contain the M2M relationship.
So, for instance, in your case where you have such a relationship between
User and Group, you would also have a third table, perhaps called UserGroup,
which maintains the relationships between rows in the User table and rows in
the Group table. Xdoclet supports this via the @jboss.relation-table tag as
seen in the following example:
/**
* @ejb.interface-method
* @ejb.relation
* name="User-Group"
* role-name="Users-are_in-Groups"
* @jboss.relation-table
* table-name="usergroup"
* create-table="${jboss.create.table}"
* remove-table="${jboss.remove.table}"
* @jboss.relation
* fk-constraint="false"
* related-pk-field="id"
* fk-column="groupId"
*/
public abstract Set getGroups();
public abstract void setGroups(Set groups);
I hope this helps.
Joel Rives
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Nathaniel
Rahav
Sent: Monday, March 31, 2003 5:51 PM
To: [EMAIL PROTECTED]
Subject: [Xdoclet-user] Many to Many M:N CMR example ?
Hello,
Does anyone have a working Many to Many CMR example ?
Additionally, are there any words of advice as to how to implement a
users & groups scheme for J2EE (JBoss) with XDoclet ?
Here is what I have done and where I got stuck:
I have the most standard Users and Groups configuration:
User Table Group Table Permissions Table
---------- ----------- -------------------
USERNAME (PK) GROUPNAME (PK) USERNAME (references USER )
PASSWORD DESCRIPTIN GROUPNAME (references GROUP )
As per Ed Roman's "Mastering EJB 2" book, I decided to go with the
approach of splitting my Many:Many CMR relation into 2 N:1 relations
I have a User EJB, a Group EJB, and a Permission EJB ,
with an ejb.relation from User (1) to Permission (many)
and an ejb.relation from Group (1) to Permission (many)
all is well in my code, and when I deploy I get the database schema
created exactly as desired. But here is where I got stuck :
The code generated for UserCMP and GroupCMP creates a new PermissionLocal
in each of their addPermission ( PermissionValue ) methods.
So, I cannot possibly add the same Permission object to 2 different
EJBs because they each will create a new row with the FK of the other set
to NULL .
So I'm wondering , how to do this ? I couldnt find any code examples of a
M:N CMR with a mapping table using XDoclet.
Any advice ? Am I going the wrong direction with this (very standard)
problem ? Any other solutions for User-Group patterns in EJB ?
Thanks in Advance,
Nathaniel
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
_______________________________________________
xdoclet-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-user