0 Replies Latest reply on Feb 24, 2006 10:43 AM by milan wölke

    strategy for deletes on many to many relationships

    milan wölke Newbie

      hello,
      does someone know a way to handle deletes of entities which are part of a manytomany relationship. especially when cascading deletes.

      I have two entity classes A and B.
      A references a set of B, and B references a set of A. deletes on B should be cascaded to all As referenced by B. Is there a way to have the entitymanager cascade deletes on A to B only if there are no more As dependent on B?

      The only way I know to do this, is to check the state of the relationship before removal myself. The problem is, that this logic would be outside the entitybean, since there is a entitymanager needed to delete Bs, which are no longer in use by other As. Of course I could create a entitybean method which would require the entitymanager as parameter, but i think, i hope there is a better way, i'm not aware of.

      Any comments on this topic are welcome.

      thanx in advance, milan wölke