Hello,
I'm trying to implement CMP 2.0 one to many bi directional relation in Jboss tomcat 3.0.4.I have to classes. One called Individual and the other is called
AccountEmail. The application works without a trouble in Weblogic 7.0 without any problem.
The bidirectional relationship is as follows,
(1) Individual ---> many AccountEmail (1 -> 0..m) (cmr field is accountemails)
(2) AccountEmail ----> one Individual (1-> 1) (cmr is individual)
In the IndividualBean class I have these methods to form the relationships
//abstract accessor and Mutator
public abstract java.util.Collection getAccountemails();
public abstract void setAccountemails(java.util.Collection accountemails);
//and an add Method to add a single instance of AccountEmail to Individual
public void addAccountEmail(LocalAccountEmail accountemail){
getAccountemails().add(accountemail);
}
In the AccountEmailBean class I have the following methods to form the relationship
//abstract accessor and Mutator
public abstract void setIndividual(LocalIndividual individual);
public abstract LocalIndividual getIndividual();
I have defined the relationsuip in the descriptors as follows,
In ejb-jar.xml
================
<ejb-relation>
<ejb-relation-name>individual-accountEmail</ejb-relation-name>
<ejb-relationship-role>
<description>individual</description>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>individual</description>
<ejb-name>Individual</ejb-name>
</relationship-role-source>
<cmr-field>
<description>accountEmail</description>
<cmr-field-name>accountemails</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<description>accountEmail</description>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<description>accountEmail</description>
<ejb-name>AccountEmail</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
<ejb-relation-name>accountEmail-individual</ejb-relation-name>
<ejb-relationship-role>
<description>accountEmail</description>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>accountEmail</description>
<ejb-name>AccountEmail</ejb-name>
</relationship-role-source>
<cmr-field>
<description>individual</description>
<cmr-field-name>individual</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<description>individual</description>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>individual</description>
<ejb-name>Individual</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
In jbosscmp-jdbc.xml
=====================
<ejb-relation>
<ejb-relation-name>individual-accountEmail</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>personid</field-name>
<column-name>personid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
<ejb-relation-name>accountEmail-individual</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>personid</field-name>
<column-name>personid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
when I tried to deploy this this gave me a Duplicate key Exception. I totally removed the relationship declereration in the
jbosscmp-jdbc.xml file and the container deployed the aplication using the standard form of column mapping by taking the relations in ejb-jar.xml.This created
to additional columns, not one column like it is done by weblogic. Then I changed the jbosscmp-jdbc.xml desciptor entries to avoid the duplicate key
exception like this.
<ejb-relation>
<ejb-relation-name>individual-accountEmail</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>personid</field-name>
<column-name>personid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>
<ejb-relation>
<ejb-relation-name>accountEmail-individual</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>AccountEmailRelationshipRole</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>IndividualRelationshipRole</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>personid</field-name>
<column-name>personid2</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
This timeit was able to deploy my application and it created two columns named personid and personid2 in the database table for
AccountEmail Bean.It looked like the things work well. But it failed without giving any error. The reason was
the application doesn't set the reverse reference from AccountEmail to the Individual in the personid2 column in the database.
When we query for the account email bean and try to retireve its corresponding individual it returns null.
The reason could be that when I added the account email using
public void addAccountEmail(LocalAccountEmail accountemail){
getAccountemails().add(accountemail);
}
Definitely the container only completed one path of the Bi directional relationship.
Is there some thing wrong in the way I'm doing it in the Jboss. Can some one please help me out in this.
Regards!!!
Dulshan De Silva
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
