FindByForeignKey failed
hubs2121 Feb 12, 2002 11:13 AMHello,
I tried a simple CMR example using two tables as folows:
parent --> parentid, name
child --> childid, name, parentid
where parentid in the child table is the Foreign Key to the parent table.
The problem occurs when I try to call the cmr accessor method getChilds( ), I get the following error:
The Parent is:
1 John Smith
The Children are:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.ServerException: FindByForeignKey failed
Embedded Exception
Column not found: Unknown column 'parent_parentid' in 'where clause'; nested exception is:
javax.ejb.EJBException: FindByForeignKey failed
Embedded Exception
Column not found: Unknown column 'parent_parentid' in 'where clause'
Why is it calling the foreign key field "parent_parentid" when it should be just "parentid"? Here is my jbosscmp-jdbc.xml:
<jbosscmp-jdbc>
java:/mySQLDS
<datasource-mapping>mySQL</datasource-mapping>
<enterprise-beans>
<ejb-name>Child</ejb-name>
<table-name>child</table-name>
<cmp-field>
<field-name>childid</field-name>
<column-name>childid</column-name>
</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>parentid</field-name>
<column-name>parentid</column-name>
</cmp-field>
<ejb-name>Parent</ejb-name>
<table-name>parent</table-name>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>
<cmp-field>
<field-name>parentid</field-name>
<column-name>parentid</column-name>
</cmp-field>
</enterprise-beans>
<ejb-relation>
<ejb-relation-name>parent-child</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>parent-has-child</ejb-relationship-role-name>
<fk-constraint>true</fk-constraint>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>child-has-parent</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>parentid</field-name>
<column-name>parentid</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>
</jbosscmp-jdbc>
When I change the column name in my database to parent_parentid it works fine, but the mapping in jbosscmp-jdbc.xml should take care of that and allow me to call it whatever I want, no?
Any ideas?
Thanks,
Steve