5 Replies Latest reply on Jul 20, 2002 11:57 PM by dsundstrom

    One to Many Remove Problem

    lcranford

      I have a simple Order-LineItem Uni-Directional One-to-Many Relationship defined between two EntityBeans (with cascade delete defined on the many side, LineItem). I'm using relation-table-mapping, so I have three tables (tb_Orders, tb_LineItems and tb_Orders_LineItems). Everything is working as expected, but now I want to implement a removeAllLineItems() on my OrderBean. I thought that I could simple invoke the getLineItems().clear() method to perform this use case (Deleting from both the tb_Orders_LineItems and tb_LineItems table). However, only the records in the relation table is being deleted, thus leaving orphaned records in tb_LineItems. How do I correctly implement this on JBoss-3.0.0? Note: I was going to just iteratate over the collection calling the EJBLocalObject.remove(), but according to the EJB 2.0 spec (ref: 10.3.6.1), the container will/should throw an IllegalStateException. Do I call Iterator.remove(), instead?

        • 1. Re: One to Many Remove Problem
          dsundstrom

          Yes iterator.remove(). It in the spec section 10.3.6.1.

          • 2. Re: One to Many Remove Problem
            lcranford

            Thanks,

            I'll change it.

            Lance

            • 3. Re: One to Many Remove Problem
              lcranford

              Here's the code I have that's in question.



              public void removeAllLineItems()
              {
              Collection lineItems = getLineItems(); //CMR field

              for(Iterator iter = lineItems.iterator();iter.hasNext();)
              {
              LineItemLocal lineItem = (LineItemLocal)iter.next();

              iter.remove();
              }
              }



              Again, upon inspection of the database, the relationship records are deleted, but the actual Entity table (tb_LineItems) are not. Here's the item I found in the logs

              2002-06-25 20:15:53,694 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCDeleteRelationsCommand.Order] Executing SQL: DELETE FROM TB_ORDER_LINEITEMS WHERE (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?) OR (line_item_id=? AND order_id=?)
              2002-06-25 20:15:53,704 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCDeleteRelationsCommand.Order] Rows affected = 10

              There seems to be a missing call to the JDBCRemoveEntityCommand class for the LineItem Entity in jboss. I was told that a call iter.remove() would do this. Is this a bug?

              • 4. Re: One to Many Remove Problem
                jocsch

                I face the same problem. Is there a solution for it?

                • 5. Re: One to Many Remove Problem
                  dsundstrom

                  This looks like a bug I just fixed in cvs Branch_3_0 and HEAD.