Done, thanks for your help.
-Noah Please log a bug: I've tried it in 2.4.2 and it hasn't generated CASCADE ON DELETE
Please log this example with the bug.
Thanks, Andrei
On 7/23/2013 10:54 AM, Noah White wrote:
I'm going to go ahead and file a bug for this case but I don't suppose you could try a @OneToOne test? I created the following test entities and added them to my project to try this out.
Here's the DDL these two entities generated for me:
CREATE TABLE BAR (ID NUMBER(19) NOT NULL, FOO_ID NUMBER(19) NULL, PRIMARY KEY (ID))
CREATE TABLE FOO (ID NUMBER(19) NOT NULL, PRIMARY KEY (ID))
ALTER TABLE BAR ADD CONSTRAINT FK_BAR_FOO_ID FOREIGN KEY (FOO_ID) REFERENCES FOO (ID)
And the entity classes:
package com.work.entity;
import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id <http://javax.persistence.id/>; import javax.persistence.OneToOne; import java.io.Serializable;
/** * Created by nwhite on 7/22/13. */ @Entity public class Bar implements Serializable {
private static final long serialVersionUID = 1L;
@Id private long id;
@OneToOne(fetch = FetchType.LAZY) private Foo foo;
public long getId() { return id; }
public void setId(long id) { this.id <http://this.id/> = id; }
public Foo getFoo() { return foo; }
public void setFoo(Foo foo) { this.foo = foo; } }
package com.work.entity;
import org.eclipse.persistence.annotations.CascadeOnDelete;
import javax.persistence.*; import java.io.Serializable;
/** * Created by nwhite on 7/22/13. */ @Entity public class Foo implements Serializable {
private static final long serialVersionUID = 1L;
@Id private long id;
@OneToOne(mappedBy = "foo", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @CascadeOnDelete private Bar bar;
public long getId() { return id; }
public void setId(long id) { this.id <http://this.id/> = id; }
public Bar getBar() { return bar; }
public void setBar(Bar bar) { this.bar = bar; } }
Thanks,
-Noah
On Jul 23, 2013, at 10:14 AM, Andrei Ilitchev <andrei.ilitchev@xxxxxxxxxx <mailto:andrei.ilitchev@xxxxxxxxxx>> wrote:
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
_______________________________________________ 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
_______________________________________________ eclipselink-users mailing list eclipselink-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/eclipselink-users
|