CMR
digitalmonkey Jul 14, 2003 8:22 AMI am trying to set up what should be a simple CMR with JBoss but although I can in fact get it working I feel sure the way it is set up cannot possibly be right.
I have a two tables CUS and USR to which I want to set up a 1-many, many-1 bidirectional relationship
The schemas of which are
CUS (This is a table of Companies)
===
CUS_UNIQUE (Key)
...
USR (This is a table of individual users)
===
USR_UNIQUE (key)
USR_CUS_UNIQUE (contains a code corresponding to a key found in CUS_UNIQUE)
The code as 'generated' is as shown below
[ejb-jar.xml]
==============
<ejb-relation-name>Company-User</ejb-relation-name>
<ejb-relationship-role>
company
<ejb-relationship-role-name>company-has-users</ejb-relationship-role-name>
One
<relationship-role-source>
company
<ejb-name>Company</ejb-name>
</relationship-role-source>
<cmr-field>
user
<cmr-field-name>allUsers</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
user
<ejb-relationship-role-name>user-belongs-to-company</ejb-relationship-role-name>
Many
<relationship-role-source>
user
<ejb-name>User</ejb-name>
</relationship-role-source>
<cmr-field>
company
<cmr-field-name>company</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
[jbosscmp-jdbc.xml]
===================
<ejb-relation>
<ejb-relation-name>Company-User</ejb-relation-name>
<foreign-key-mapping />
<ejb-relationship-role>
<ejb-relationship-role-name>company-has-users</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>uniqueId</field-name>
<column-name>CUS_UNIQUE</column-name> ****
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>user-belongs-to-company</ejb-relationship-role-name>
</ejb-relationship-role>
</ejb-relation>
However when run, JBoss complains because the field CUS_UNIQUE is not present in the USR_TBL table (and I am unable to simply change the names to suit)
If I manually change the value at the line indicated by **** to the value USR_CUS_UNIQUE (note still keeping the name as uniqueId), then the application deploys and runs under JBoss 3.2.x.
Surely this is not the right way of implementing this?