I have a strange problem with @CascadeOnDelete annotation. For instance
@Entity
public class Employee {
@Id
private long id;
private String firstName;
private String lastName;
@OneToMany(mappedBy = "parent", orphanRemoval = true, cascade = { CascadeType.ALL })
@CascadeOnDelete
private List<Employee> children;
@ManyToOne
private Employee parent;
}
eclipselink generates the following DDL:
CREATE TABLE EMPLOYEE (ID BIGINT NOT NULL, FIRSTNAME VARCHAR(255), LASTNAME VARCHAR(255), PARENT_ID BIGINT, PRIMARY KEY (ID))
ALTER TABLE EMPLOYEE ADD CONSTRAINT FK_EMPLOYEE_PARENT_ID FOREIGN KEY (PARENT_ID) REFERENCES EMPLOYEE (ID)
Note, that ON DELETE CASCADE is not generated, therefore it works not as expected.
Any ideas?
[Updated on: Tue, 11 September 2012 09:19]
Report message to a moderator