3 Replies Latest reply on May 18, 2005 5:25 PM by Emmanuel Bernard

    Cascading removed objects from multi-valued relationships

    Denis Souza Newbie


      Consider as an example a typical e-commerce application with Order and LineItem entities. There is a one-to-many relationship between these two entities. Now let's say that this relationship is annotated with Cascade=ALL. When the Order entity is persisted, all LineItems will also be persisted, naturally. The same goes for merge and remove.
      There is however a case that I just stumbled into. What happens if I my Order and LineItem objects are pesisted and I decide to remove one of the LineItems? What I thought was that a call to "remove" on the List of LineItems present in the Order object would do the trick. I could then just merge the Order object and it would update all relationships, but that's not what happened.

      If after I remove the LineItem, I call persist on Order, an entirely new order will be created in the database (without the removed LineItem).
      If I call merge, the LineItem is not removed from the database.

      My question is: Is this the correct behavior? Must I necessarily ask the entity manager to remove the specific LineItem instead of trusting it to remove while cascading, or is this something that is simply not implemented yet or maybe even a bug?