[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] @CascadeOnDelete bug
|
I was wrong, the cascadeOnDelete comment states:
* <p>For a OneToOne it can only be defined if the mapping uses a
mappedBy, and will delete the target object.
so you example was correct and mine wrong.
I ran a test that uses CaccadeOnDelete with OneToMany:
@Table(name="CMP3_FA_EMPLOYEE")
public class Employee implements Serializable, Cloneable {
...
@OneToMany(cascade=ALL, mappedBy="owner")
@PrivateOwned
@CascadeOnDelete
private Collection<PhoneNumber> phoneNumbers;
...}
@Table(name = "CMP3_FA_PHONENUMBER")
public class PhoneNumber extends PhoneNumberMappedSuperclass {
...
@ManyToOne
@JoinColumn(name = "OWNER_ID", referencedColumnName = "EMP_ID")
private Employee owner;
...}
and got cascade delete ddl:
ALTER TABLE CMP3_FA_PHONENUMBER ADD CONSTRAINT FA_PHONE_OW_FK FOREIGN
KEY (OWNER_ID) REFERENCES CMP3_FA_EMPLOYEE (EMP_ID) ON DELETE CASCADE
On 7/23/2013 9:57 AM, Noah White wrote:
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
[1] - http://wiki.eclipse.org/EclipseLink/Examples/JPA/DeleteCascade
[2] -
http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/a_cascadeondelete.htm
On Jul 23, 2013, at 9:38 AM, Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx
<mailto:andrei.ilitchev@xxxxxxxxxx>> wrote:
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 <mailto:eclipselink-users@xxxxxxxxxxx>
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx <mailto: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