1 Reply Latest reply on Aug 27, 2002 5:00 AM by jcordes

    Remove a collection in CMR

    a13519

      JBoss 3.0.0 + Mysql + JDK1.4

      I have completed a 1:n unidirection CMR system (entity bean A and B), the relation is mapped by foreign key. Now what I do is to delete a set of entity B from A's collection.

      What I have are B's primary keys. I do it this way:

      1, I built a java.util.Collection r contains the all local interface of B I am going to delete. (I use findByPrimaryKey to get those lcoal interface)

      2, I'd like to make sure those Bs' local interfaces are belong to a certain A, so I get a another java.util.Collection w by call A's getBLocals(). Then I call w.removeAll(r) to remove r from w.

      As the result, I found the B wasn't removed actually, but the foreign key is assigned to null, the records are exist. Is there any wrong in my work or the best way I should do? Appreciated your replies!

      Best Regards,
      a13519

        • 1. Re: Remove a collection in CMR
          jcordes

          Hi a13519 !

          Did you call remove() on each of the B's local interfaces ? If not, the B's are not being deleted, they are only removed from the relationship, so that the primary key is set to null is a perfect behavior.

          Hope it helps,

          Jochen.