4 Replies Latest reply on Jul 4, 2006 10:14 AM by horst21

    ManyToMany: delete causes a violation of foreign key constra

    horst21 Newbie

      Hello,
      I got a Problem deleting persistent EJB3 entity objects:

      I got a class PointOfPayment that has a ManyToMany relation to the class Account.
      When I try to delete a persistent PointOfPayment object that has an entry in the relation-collection to account, I got an exception:

      org.apache.derby.client.am.SqlException: DELETE on table 'POINT_OF_PAYMENT' caused a violation of foreign key constraint 'FK712B399B71820D81' for key (98304). The statement has been rolled back.

      Query q = em.createQuery("delete PointOfPayment");
      q.executeUpdate();
      


      I guess that the problem is that entries in the join-table of the ManyToMany relation are not deleted automatically. Do I have to take care of the entries in the relationtable myself? Do I have to remove the account object from the relation before deleting the PointOfPayment?

      The database I am using is: apache derby 10.1.2.1.
      The JBoss ejb3 Version is: jboss-EJB-3.0_RC6

      thanks for your help, cheers.