cascading-deletes

JPA 2.0 orphanRemoval=true VS on delete Cascade

六月ゝ 毕业季﹏ 提交于 2019-11-26 04:04:19
问题 I am a little confused about the JPA 2.0 orphanRemoval attribute. I think I can see its is needed when I use my JPA provider\'s DB generation tools to create the underlying database DDL to have an ON DELETE CASCADE on the particular relation. However, if the DB exists and it already has an ON DELETE CASCADE on the relation, is this not enough to cascade the deletion appropriately? What does the orphanRemoval do in addition? Cheers 回答1: orphanRemoval has nothing to do with ON DELETE CASCADE .

Entity Framework (EF) Code First Cascade Delete for One-to-Zero-or-One relationship

空扰寡人 提交于 2019-11-26 01:39:57
问题 Following the \"Code First Modeling\" section of the Pluralsight \"Getting Started with Entity Framework 5\" course by Julie Lerman, I created two POCO classes with a one-to-zero-or-one relationship: a parent (User) and an optional child (UserDetail). User and UserDetail data model diagram (click to view). Notice in the diagram that the UserId property is a primary key and a foreign key for UserDetail . Relevant code: public class User { //... [Key] [DatabaseGenerated(DatabaseGeneratedOption