I'm grinding my way though the IBM CMP tutorial, and converting the concepts to JBoss 
for practice.  I am backending my application with MySQL.

Everything was going smoothly with only minor glitches.  Mostly due to the jboss 
specific XML that the IBM tutorial doesn't cover, and since I'm using XDoclet, that 
makes it even more complicated.

Now to the problem, or perhaps it's a question if this is the way things are supposed 
to work.

I have two business method CMP EJB's User and Group.  I'll spare the full source 
unless it's requested, but the general gist of the CMP fields are:

UserBean:

  | public abstract String getEmail();  //primary key 
  | public abstract void setEmail(String email);
  | public abstract String getPassword();
  | public abstract void setPassword(String password);
  | public abstract GroupLocal getGroupMembership();  //CMR Field with group.
  | public abstract void setGroupMembership(GroupLocal groupmembership);
  | 
  | 
GroupBean:

  | public abstract String getGroupName(); //primary key
  | public abstract void setGroupName(String groupname);
  | public abstract String getDescription();
  | public abstract void setDescription(String description);
  | public abstract java.util.Collection getUsers(); //CMR field with user
  | public abstract void setUsers(java.util.Collection users);
  | 

I then proceeded to define the relation with:

ejb-jar.xml

  |       <ejb-relation >
  |          <ejb-relation-name>GroupsHaveUsers</ejb-relation-name>
  | 
  |          <ejb-relationship-role >
  |             <ejb-relationship-role-name>UsersInGroup</ejb-relationship-role-name>
  |             <multiplicity>Many</multiplicity>
  |             <relationship-role-source >
  |                <ejb-name>User</ejb-name>
  |             </relationship-role-source>
  |             <cmr-field >
  |                <cmr-field-name>groupMembership</cmr-field-name>
  |             </cmr-field>
  |          </ejb-relationship-role>
  | 
  |          <ejb-relationship-role >
  |             <ejb-relationship-role-name>GroupHasUsers</ejb-relationship-role-name>
  |             <multiplicity>One</multiplicity>
  |             <relationship-role-source >
  |                <ejb-name>Group</ejb-name>
  |             </relationship-role-source>
  |             <cmr-field >
  |                <cmr-field-name>users</cmr-field-name>
  |                <cmr-field-type>java.util.Collection</cmr-field-type>
  |             </cmr-field>
  |          </ejb-relationship-role>
  | 
  |       </ejb-relation>
  | 

jbosscmp-jdbc.xml


  |     <ejb-relation>
  |       <ejb-relation-name>GroupsHaveUsers</ejb-relation-name>
  | 
  |       <foreign-key-mapping/>
  | 
  |       <ejb-relationship-role>
  |           <ejb-relationship-role-name>UsersInGroup</ejb-relationship-role-name>
  |               <key-fields/>
  | 
  |       </ejb-relationship-role>
  |       <ejb-relationship-role>
  |           <ejb-relationship-role-name>GroupHasUsers</ejb-relationship-role-name>
  |           <key-fields>
  |              <key-field>
  |                <field-name>groupname</field-name>
  |                <column-name>groupname</column-name>
  |              </key-field>
  |           </key-fields>
  | 
  |       </ejb-relationship-role>
  |     </ejb-relation>
  | 

Now the way I understand it the container should be handling the maintenence of this 
relationship right? So when I set the GroupMembership CMP field of a UserBean object, 
the container should add that UserObject to the corresponding Group object's Users 
Collection right?  Or, since the relation should be bidirectional, if I add a 
UserLocal object to the Users Collection of a Group object then the corresponding User 
object's GroupMembership field should be updated with the latest GroupLocal, right? 

This is not the case.  After I set a User objects GroupMembership field with a 
GroupLocal object, the Group objects Users Collection is still null!  If I manually 
instatiate the Group object, create a new Collection via a type cast from ArrayList 
and add the User object to the Group objects collection, then it works.

Is the relationship not working, or is this the way it should be done?



View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3835445#3835445

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3835445


-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to