openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Miroslav Nachev" <m...@space-comm.com>
Subject Cascade on Delete is not working
Date Fri, 28 Dec 2007 18:15:09 GMT
Hi,

I have 3 tables:
- TestTable1 (test_table_1) which is master for the rest tables
    @Id
    @Column(name = "test_id", nullable = false)
    private BigDecimal testId;
    @Column(name = "is_deleted", nullable = false)
    private boolean deleted;
    @OneToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, mappedBy =
"tt1Id")
    private Collection<TestTable2> testTable2Collection;
    @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.EAGER, mappedBy =
"testTable1")
    private TestTable3 testTable3;

- TestTable2 (test_table_2)
    @Id
    @Column(name = "tt2_id", nullable = false)
    private BigDecimal tt2Id;
    @JoinColumn(name = "tt1_id", referencedColumnName = "test_id")
    @ManyToOne
    private TestTable1 tt1Id;
- TestTable3 (test_table_3)
    @Id
    @Column(name = "tt3_id", nullable = false)
    private BigDecimal tt3Id;
    @Column(name = "text_data")
    private String textData;
    @JoinColumn(name = "tt3_id", referencedColumnName = "test_id",
insertable = false, updatable = false)
    @OneToOne
    private TestTable1 testTable1;

When I try to delete some record from TestTable1 I have the following
exception:
Caused by: <openjpa-1.1.0-SNAPSHOT-r420667:606946M nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: ERROR: update or delete
on table "test_table_1" violates foreign key constraint "fk_tt2_tt1_id" on
table "test_table_2"
  Detail: Key (test_id)=(1198864038296) is still referenced from table
"test_table_2". {prepstmnt 25877218 DELETE FROM test_table_1 WHERE test_id =
? [params=(BigDecimal) 1198864038296]} [code=0, state=23503]
...


Where did I go wrong? Why I can not delete record from master table and all
records from referenced tables to be cascade deleted?


Miro.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message