我有兩個表:t_promo_program和t_promo_program_param。JPA級聯刪除:在NOT NULL列上將子FK設置爲NULL
它們由以下JPA實體表示:
@Entity
@Table(name = "t_promo_program")
public class PromoProgram {
@Id
@Column(name = "promo_program_id")
private Long id;
@OneToMany(cascade = {CascadeType.REMOVE})
@JoinColumn(name = "promo_program_id")
private List<PromoProgramParam> params;
}
@Entity
@Table(name = "t_promo_program_param")
public class PromoProgramParam {
@Id
@Column(name = "promo_program_param_id")
private Long id;
//@NotNull // This is a Hibernate annotation so that my test db gets created with the NOT NULL attribute, I'm not married to this annotation.
@ManyToOne
@JoinColumn(name = "PROMO_PROGRAM_ID", referencedColumnName = "promo_program_id")
private PromoProgram promoProgram;
}
當我刪除PromoProgram,休眠打我的數據庫有:
update
T_PROMO_PROGRAM_PARAM
set
promo_program_id=null
where
promo_program_id=?
delete
from
t_promo_program
where
promo_program_id=?
and last_change=?
我在哪裏開始尋找丟失爲問題的根源。
Upvoted爲「optional = false」位。 – 2010-04-22 20:49:29