Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] @CascadeOnDelete bug

JPA 2.0 Spec. states in 2.9 Entity Relationships:
...
The inverse side of a bidirectional relationship must refer to its owning side by use of the mappedBy...

For one-to-one bidirectional relationships, the owning side corresponds to the side that contains the corresponding foreign key.


Also the comment to CascadeOnDelete:
/**
...
* The constraint cascaded depends on the mapping, only relationship mappings are allowed.
 * The relationship should also use cascade remove, or deleteOrphans.
...


That means it should be another way around.
Either:
@OneToOne(fetch = FetchType.LAZY, optional = true, cascade = ALL)
@CascadeOnDelete
private Baz baz;
...
@OneToOne(mappedBy =  "baz", fetch = FetchType.LAZY)
private FooBar fooBar;

or:
@OneToOne(mappedBy =  "fooBar", fetch = FetchType.LAZY)
private Baz baz;
..
@OneToOne(fetch = FetchType.LAZY, cascade = ALL))
@CascadeOnDelete
private FooBar fooBar;


On 7/22/2013 4:59 PM, Noah White wrote:
Before I go ahead and file I just wanted to run this by this list.  I'm using Eclipselink 2.3.2v20111125-r10461 (bundled w/GlassFish 3.1.2.2) and have two entity object which share a @OneToOne bi-directional mapping. eg:

@OneToOne(mappedBy =  "fooBar", fetch = FetchType.LAZY, optional = true, cascade = ALL)
@CascadeOnDelete
private Baz baz;

and on the other end

@OneToOne(fetch = FetchType.LAZY)
private FooBar fooBar;


In my persistence.xml I have 'eclipselink.ddl-generation' set to 'create-tables'.  This is against an Oracle database.

When I examine the generated DDL I do not see the expected ON DELETE CASCADE on the constraint.

-Noah
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top