Andrei -
Thanks for your reply. This advice is contrary to the Eclipselink wiki examples here [1] and here [2] which show the annotation on the side containing the mappedBy.
I also tried switching the annotation around as you suggested in the first part of your example and regenerated the schema via redeployment and I am still not seeing ON DELETE CASCADE in the generated DDL.
-Noah
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
_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|