You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Alexander Saint Croix <sa...@gmail.com> on 2008/01/11 19:54:33 UTC

Cascade delete for ManyToOne bidirectional mappings from non-controlling side

Hello,

I have a class "Foo" that has a ManyToOne bidirectional association with a
class "Bar".  The relationship is set up so that if a Foo bean is deleted,
the Bar bean must also be deleted, but not vice versa.  However, my tests
verify that this is not happening.  I'm doing something wrong.

Any ideas where I've gone astray?

Cheers,
--
Alexander R. Saint Croix



My annotations look like this:


@Entity
> public class Foo {
>
>     @Id
>     @GeneratedValue
>     private long ID;
>
>     @OneToMany(cascade=CascadeType.ALL, mappedBy="foo")
>     private Set<Bar> bars = new HashSet<Bar> ();
>
> ...
> }
>
>
> @Entity
> public class Bar {
>
>     @Id
>     @GeneratedValue
>     private long ID;
>
>     @ManyToOne(cascade = {
>             CascadeType.PERSIST,
>             CascadeType.REFRESH,
>             CascadeType.MERGE})
>     private Foo foo;
>
> ...
> }
>