Either ALL or DELETE will delete the related entities when deleting the owner.
You can specify the other cascade types, such as:
cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}
--
Luis Fernando Planella Gonzalez
Em Quarta-feira 14 Outubro 2009, às 13:49:32, Daryl Stultz escreveu:
> Hello, I have a ManyToMany relation of A to B like so:
>
> in A entity:
>
> @ManyToMany(cascade = CascadeType.ALL)
> @JoinTable(name = "special_a_to_b_table",
> joinColumns = { @JoinColumn(name = "a_id", referencedColumnName =
> "a_id") },
> inverseJoinColumns = { @JoinColumn(name = "b_id", referencedColumnName =
> "b_id") }
> )
>
> private List<B> specialBList;
>
> The special_a_to_b_table is a simple join table with foreign keys to A and
> B.
>
> I was thrilled to find that adding B instances to specialBList and merging
> the A instance inserted the special_a_to_b_table records. I was horrified
> to find that deleting the A instance deletes the B instances as well! I
> don't want to delete the B instances but the special_a_to_b_table records
> representing the join. What is the right way to do this? For now I have
> removed CascadeType.DELETE from the mix and I'm using a foreign key
> cascade in the database.
>
> Thanks.
>
> --Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:[email protected]
>