Cascade

Doctrine: cascade=“remove” vs orphanremoval=true

半腔热情 提交于 2019-11-26 18:56:42
问题 What is the difference between the 2 options above? When is it preferable to choose each option? 回答1: The basic difference between them is: When using the orphanRemoval=true option Doctrine makes the assumption that the entities are privately owned and will NOT be reused by other entities. If you neglect this assumption your entities will get deleted by Doctrine even if you assigned the orphaned entity to another one. Say your User has one-to-many relation to Comment . If you are using

cascade={“remove”} VS orphanRemoval=true VS ondelete="CASCADE

徘徊边缘 提交于 2019-11-26 18:46:24
问题 I tried to gather few information about those following way to delete automatically child entity when a parent entity is deleted. Seems that the most common way is to use one those three annotation: cascade={"remove"} OR orphanRemoval=true OR ondelete="CASCADE" . I am a bit confuse about the third one: ondelete="CASCADE" , as explanation in doctrine official documentation about this one are very scarce) and I would love if someone could confirm me the following information I gathered and

Should I use the CASCADE DELETE rule? [duplicate]

こ雲淡風輕ζ 提交于 2019-11-26 18:03:35
问题 Duplicate of: When/Why to use Cascading in SQL Server? I've always been too scared to use DELETE CASCADE, but as I get more confident (lazy :D), I'm thinking how bad can it be, is it best practise to use it or should I avoid it and clean up my foreign keys etc the old fashioned way (with stored procedures)? 回答1: ON DELETE CASCADE is fine, but only when the dependent rows are really a logical extension of the row being deleted. For example, it's OK for DELETE ORDERS to delete the associated

What is the problem with foreign key cascade multiple paths and cycles?

折月煮酒 提交于 2019-11-26 17:13:39
问题 In MSSQL 2005 I just struck the infamous error message: Introducing FOREIGN KEY constraint XXX on table YYY may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Now, StackOverflow has several topics about this error message, so I've already got the solution (in my case I'll have to use triggers), but I'm curious as to why there is such a problem at all. As I understand it, there are basically two scenarios

JPA 2.0 orphanRemoval=true VS on delete Cascade

不羁岁月 提交于 2019-11-26 16:58:14
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 axtavt orphanRemoval has nothing to do with ON DELETE CASCADE . orphanRemoval is an entirely ORM-specific thing . It marks "child" entity to be removed when it's no

When/Why to use Cascading in SQL Server?

血红的双手。 提交于 2019-11-26 14:55:26
When setting up foreign keys in SQL Server, under what circumstances should you have it cascade on delete or update, and what is the reasoning behind it? This probably applies to other databases as well. I'm looking most of all for concrete examples of each scenario, preferably from someone who has used them successfully. Joel Coehoorn Summary of what I've seen so far: Some people don't like cascading at all. Cascade Delete Cascade Delete may make sense when the semantics of the relationship can involve an exclusive "is part of " description. For example, an OrderLine record is part of its

Hibernate: How to use cascade in annotation?

半城伤御伤魂 提交于 2019-11-26 14:22:29
问题 How can I use cascade and annotations in hibernate? But I stay with a doubt: I have this situation: public class Package(){ @OneToOne(cascade=CascadeType.PERSIST) private Product product; @OneToOne(cascade=CascadeType.PERSIST) private User user; .. } When I try to session.save(package) , an error occurs. I don't want to save product and package. I just want to initialize and set them into my package object. Is that possible? 回答1: See the hibernate documentation which is very clear on this

MySQL on delete cascade. Test Example

老子叫甜甜 提交于 2019-11-26 14:06:13
问题 I am wondering about this test question. I prepared the example myself and tested it but I still feel unsure of the answer. With the following: CREATE TABLE foo ( id INT PRIMARY KEY AUTO_INCREMENT, name INT ) CREATE TABLE foo2 ( id INT PRIMARY KEY AUTO_INCREMENT, foo_id INT REFERENCES foo(id) ON DELETE CASCADE ) As far as I can see the answer is: a. Two tables are created Although there are also: b. If a row in table foo2, with a foo_id of 2 is deleted, then the row with id=2 in the table foo

SQL ON DELETE CASCADE, Which Way Does the Deletion Occur?

独自空忆成欢 提交于 2019-11-26 11:54:46
问题 If I have two relations in a database, like this: CREATE TABLE Courses ( CourseID int NOT NULL PRIMARY KEY, Course VARCHAR(63) NOT NULL UNIQUE, Code CHAR(4) NOT NULL UNIQUE ); CREATE TABLE BookCourses ( EntryID int NOT NULL PRIMARY KEY, BookID int NOT NULL, Course CHAR(4) NOT NULL, CourseNum CHAR(3) NOT NULL, CourseSec CHAR(1) NOT NULL ); and I establish a foreign key relationship between the two, like this: ALTER TABLE BookCourses ADD FOREIGN KEY (Course) REFERENCES Courses(Code) ON DELETE

How do I use on delete cascade in mysql?

自作多情 提交于 2019-11-26 10:33:00
I have a database of components. Each component is of a specific type. That means there is a many-to-one relationship between a component and a type. When I delete a type, I would like to delete all the components which has a foreign key of that type. But if I'm not mistaken, cascade delete will delete the type when the component is deleted. Is there any way to do what I described? Here's what you'd include in your components table. CREATE TABLE `components` ( `id` int(10) unsigned NOT NULL auto_increment, `typeId` int(10) unsigned NOT NULL, `moreInfo` VARCHAR(32), -- etc PRIMARY KEY (`id`),