1 Reply Latest reply on Feb 25, 2003 3:24 AM by conradt

    CMR cascade-delete problem with 1:Many Unidirectional Relati

    conradt

      I have a simple 1:many relationship: a Person can have many Phone Numbers. When I delete a person, I want to have all phone numbers of this person to be deleted too (using cascade-delete).
      I'm using Jboss3.0.4 and Firebird1.0.

      [B]
      My problem:

      Deleting a person, who has NO phone numbers in the phone-Table works fine.
      BUT I get an error when I try to delete a person that has one or more corresponding phone entries.
      I use the method personHome.remove(new Integer(2)); and the person with primary key 2 exists.[/B]
      The person is not been deleted and I get following message:

      2003-02-24 23:09:13,813 ERROR [org.jboss.ejb.plugins.LogInterceptor] RuntimeException:
      java.lang.NullPointerException
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityEJBLocalObject(BaseLocalContainerInvoker.java:199)
      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.getEntityLocalCollection(BaseLocalContainerInvoker.java:210)
      at org.jboss.ejb.plugins.cmp.jdbc.bridge.RelationSet.toArray(RelationSet.java:246)
      at java.util.ArrayList.(ArrayList.java:132)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.removeFromRelations(JDBCRemoveEntityCommand.java:136)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCRemoveEntityCommand.execute(JDBCRemoveEntityCommand.java:70)
      at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.removeEntity(JDBCStoreManager.java:635)
      at org.jboss.ejb.plugins.CMPPersistenceManager.removeEntity(CMPPersistenceManager.java:542)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.removeEntity(CachedConnectionInterceptor.java:431)
      at org.jboss.ejb.EntityContainer.remove(EntityContainer.java:507)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      [...]


      ejb-jar.xml
      -----------

      <ejb-relation>
      <ejb-relation-name>Person-Phone</ejb-relation-name>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Person-has-phone</ejb-relationship-role-name>
      One
      <relationship-role-source>
      <ejb-name>PersonEJB</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Phone-belongs-to-person</ejb-relationship-role-name>
      Many
      <cascade-delete/>
      <relationship-role-source>
      <ejb-name>PhoneEJB</ejb-name>
      </relationship-role-source>
      <cmr-field>
      <cmr-field-name>tel_person</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      </ejb-relation>



      jboss-cmpjdbc.xml
      ------------------

      <ejb-relation>
      <ejb-relation-name>Person-Phone</ejb-relation-name>
      <foreign-key-mapping/>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Person-has-phone</ejb-relationship-role-name>
      <key-fields>
      <key-field>
      <field-name>p_id</field-name>
      <column-name>tel_person</column-name>
      </key-field>
      </key-fields>
      </ejb-relationship-role>
      <ejb-relationship-role>
      <ejb-relationship-role-name>Phone-belongs-to-person</ejb-relationship-role-name>
      <key-fields/>
      </ejb-relationship-role>
      </ejb-relation>