Hello,
I have a problem using Container Managed Relationships with 2 EJBs with
Container Managed Persitencies. Both EJBs have a composed Primary Key
(consisting of two Long-Objects). After creating a CMR with the two EJBs
(bidirectional, one to many) I get the following error from JBoss:
16:28:22,305 WARN [ServiceController] Problem starting service
jboss.j2ee:service=EjbModule,module=mda2-EJBModule.jar
org.jboss.deployment.DeploymentException: Atleast one role of a foreign-key
mapped relationship must have key fields (or <primkey-field> is missing from
ejb-jar.xml): ejb-relation-name=SPtoPD
I tried implementing the relationship in jbosscmp-jdbc.xml without any
change. Searching the Web resulted in some hints, that the reason is the
composed PK, but I found no solution that helped me. Is it a generell
Problem to use composed Keys in CMRs? Are there any things I have to
mention? Poorla I found no example using EJBs with composed PKs in CMRs...
Plese help...
tschau
Sascha Effert
Frank Langelage - 20 Sep 2006 20:37 GMT
> I have a problem using Container Managed Relationships with 2 EJBs with
> Container Managed Persitencies. Both EJBs have a composed Primary Key
> (consisting of two Long-Objects). After creating a CMR with the two EJBs
> (bidirectional, one to many) I get the following error from JBoss:
>
> mention? Poorla I found no example using EJBs with composed PKs in CMRs...
Here is one example that works for me with JBoss 4.0.4-GA:
Table msgpa has a PK of msghd_serial+part_no, Table msgln has a PK of
msghd_serial+part_no+line_no. So this a one to many relation with a
composed PK/FK.
The DD is generated by XDoclet based on:
* @ejb.relation
* name="Msgpa-Msgln"
* role-name="1-msgpa-n-msgln"
* multiple="yes"
* target-multiple="no"
* target-ejb="Msgln"
* target-role-name="n-msgln-1-msgpa"
* @jboss.target-relation
* related-pk-field="msghdSerial"
* fk-column="msghd_serial"
* @jboss.target-relation
* related-pk-field="partNo"
* fk-column="part_no"
From this I get in ejb-jar.xml:
<ejb-relation >
<ejb-relation-name>Msgpa-Msgln</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>1-msgpa-n-msgln</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source >
<ejb-name>Msgpa</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>msgln</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>n-msgln-1-msgpa</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source >
<ejb-name>Msgln</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
And in jbosscmp-jdbc.xml:
<ejb-relation>
<ejb-relation-name>Msgpa-Msgln</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>1-msgpa-n-msgln</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>msghdSerial</field-name>
<column-name>msghd_serial</column-name>
</key-field>
<key-field>
<field-name>partNo</field-name>
<column-name>part_no</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>n-msgln-1-msgpa</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
</ejb-relation>