0 Replies Latest reply on Sep 6, 2004 10:31 PM by sbrbot

    CMR and NOT NULL foreign key

    sbrbot

      Although I searched throughout this Forum I haven't found a solution for this problem.

      I have 1:M CMR between Person and Addresses ejbs. Tables are PERSON(PersID,attributes) and ADDRESS(AddrID,PersID,attributes) where PersID is NOT NULL foreign key referencing PERSON(PersID). When I want to remove all Person's addresses (without removing person itself) I have the following code:

      Collection addresses=persLocal.getAddresses();//CMR
      for(Iterator i=addresses.iterator();i.hasNext();)
      {
       i.next();
       i.remove();
      }


      but it does not work since JBoss tries before deletion to destroy relationship between Person and its Address by mains to set foreign key to NULL and that is not allowed by underlying database!

      Actually I cannot remove CMR related beans! Why JBoss tries to set PersID in ADDRESS table to NULL before removing it? It is not necessary at all (with or without NOT NULL foreign key)!