2013-06-12 2 views
0

그래서이 내 설정이다 : 나는이 기록을 포함 클래스 RecordNotification의 개체도 제거 할 클래스 레코드의 개체를 삭제 JPA 제거 주석

public class Record { 
    //Stuff 
} 

public class RecordNotification { 
    @ What Comes Here? 
    private Record record; 
} 

. RecordNotification 타입의 Object는 항상 같은 레코드를 포함하고 있습니다. Record는 RecordNotification을 알지 못합니다. RecordNotification이 제거되면 다른 일은 발생하지 않습니다.

답변

3

해당 RecordNotification에 포인트를 기록하는 속성을 추가해야합니다. 그런 다음 계단식 삭제로 표시 할 수 있습니다. 이처럼 :

@Entity 
public class Record { 
    @Id 
    private int id; 
    @OneToOne(mappedBy="record", cascade={CascadeType.REMOVE}) 
    private RecordNotification notification; 

    public Record(int id) { 
     this.id = id; 
    } 

    protected Record() {} 
} 

@Entity 
public class RecordNotification { 
    @Id 
    private int id; 
    @OneToOne 
    private Record record; 

    public RecordNotification(int id, Record record) { 
     this.id = id; 
     this.record = record; 
    } 

    protected RecordNotification() {} 
} 

생성 된 DDL했다 :, 커밋 다음 Record을 삭제하고 RecordNotification 멀리가는 것을주의하는 RecordRecordNotification을 만드는 :이 작동하는지 확인했습니다

create table Record (
    id integer not null, 
    primary key (id) 
); 

create table RecordNotification (
    id integer not null, 
    record_id integer, 
    primary key (id) 
); 

alter table RecordNotification 
    add constraint FKE88313FC6EE389C1 
    foreign key (record_id) 
    references Record; 

.

나는 Hibernate 4.1.4.Final을 사용했다. 이것이 당신을 위해 작동하지 않는다면, 나는 EclipseLink에서 버그 또는 오작동을 의심합니다.

+0

나는 그것이 나에게 오류를 주려고했다 : (기록은 클래스 A, recordNotification 클래스 B) – eclipse

+2

글쎄 그건 부끄러운 일이다. –

+0

예외 : [EclipseLink-4002] (Eclipse Persistence Services - 2.1.2.v20101206-r8635) : org.eclipse.persistence.exceptions.DatabaseException 내부 예외 : java.sql.SQLException : 무결성 제약 조건 위반 FK_RECORDNOTIFICATION_RECORD_ID -8 전화 : T_RECORD에서 삭제하는 WHERE (? ID =) 이 \t 바인드 => [qTBN-UatHhlnlX이-XHFrrvzKOPQJ4iCfMCWy__3LxcyM] – eclipse