1-N remove() problem
lmagee Sep 24, 2002 10:00 PMI have two tables, ItemType and Item, which have a 1-N relationship. ItemType is read-only, and should never have rows inserted or deleted during the lifetime of the application (ie it is a control table). I've modelled this with CMP, where Item has a CMR field called ItemType. Everything works fine, except when I remove an Item instance which has the *only* reference to a given ItemType instance - this is removed as well. For instance, if I have two Items, A & B, with an ItemType 'PRODUCT', I get the following behavior:
remove instance A:
DELETE FROM ITEM WHERE ITEM_ID = 'A'
remove instance B:
DELETE FROM ITEMTYPE WHERE ITEMTYPE_ID = 'PRODUCT'
DELETE FROM ITEM WHERE ITEM_ID = 'B'
Should this be the case? I've not specified <cascade-delete> anywhere. The relevant portions of my ejb-jar and jbosscmp-jdbc files are listed below. Any help on this (is it a bug? or incorrect config?) would be greatly appreciated.
ejb-jarxml:
<ejb-relation >
<ejb-relation-name>item-itemtype</ejb-relation-name>
<ejb-relationship-role >
<ejb-relationship-role-name>item-is-a-itemtype</ejb-relationship-role-name>
Many
<relationship-role-source >
<ejb-name>Item</ejb-name>
</relationship-role-source>
<cmr-field >
<cmr-field-name>itemType</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role >
<ejb-relationship-role-name>itemtype-has-item</ejb-relationship-role-name>
One
<relationship-role-source >
<ejb-name>ItemType</ejb-name>
</relationship-role-source>
</ejb-relationship-role>
</ejb-relation>
jbosscmp-jdbc.xml:
<ejb-relation>
<ejb-relation-name>item-itemtype</ejb-relation-name>
<foreign-key-mapping/>
<ejb-relationship-role>
<ejb-relationship-role-name>item-is-a-itemtype</ejb-relationship-role-name>
<key-fields/>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>itemtype-has-item</ejb-relationship-role-name>
<key-fields>
<key-field>
<field-name>itemTypeID</field-name>
<column-name>ITEMTYPE_ID</column-name>
</key-field>
</key-fields>
</ejb-relationship-role>
</ejb-relation>