2 Replies Latest reply on Jun 24, 2007 3:03 PM by thepriz

    Bidirectional Cascade

      When you put declare a bidirectional relationship in a OneToMany and ManyToOne relationship and put a cascade=CascadeType.ALL on the OneToMany declaration is the cascade in both directions or only on the OneToMany relationship? In other words if I have a airplane with passangers and I remove a passenger will it delete the airplane?

      And how do I get it to set a ManyToOne relationship null if the otherside is deleted?

      I have been working with Cascades but I just can't seem to get it to work right.

      Thanks in advance,
      Dennis Przybyla

        • 1. Re: Bidirectional Cascade
          waynebaylor

          The cascade setting will only work in one direction, so if you put it on the OneToMany relationship you can remove entities from the collection without fear of deleting the parent.

          As for the second question, if you have CascadeType.ALL set, then you won't be able to set the ManyToOne side because it will be deleted when the other side is deleted.

          Hope that helps :)

          • 2. Re: Bidirectional Cascade

            Yes, that helps a lot. It may explain why I was seeing some problems. I will have to experiment more.