Cascade

Doctrine: cascade=“remove” vs orphanremoval=true

北战南征 提交于 2019-11-27 17:23:14
What is the difference between the 2 options above? When is it preferable to choose each option? Serge Kvashnin 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" , you can remove the reference for Comment from one User , and then attach that

Understanding Doctrine Cascade Operations

若如初见. 提交于 2019-11-27 17:23:06
I want to check my understanding of cascade operations on Doctrine associations. For the purpose of this question, I have two models: Customer and Insuree . If I define a many to many relationship between a Customer and Insuree and set cascade{"all"} , I understand that this will: Adding a new insuree to a customer will persist this insuree and create an association in the join table. Removing an insuree from the collection will detach the insuree from the customer and detach the customer from the insuree. Deleting the customer will delete all insurees associated with the customer. This is the

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

时光总嘲笑我的痴心妄想 提交于 2019-11-27 16:51:21
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 understand from my research on the net and experience... WHAT IT DOES cascade={"remove"} ==> the entity on

Hibernate EntityManager: remove referenced entity not working

余生长醉 提交于 2019-11-27 16:48:01
问题 I'm currenetly trying hard to delete an entity, that is involved in various relations (Only @ManyToOne ) - However, Hibernate does not delete anything - after calling em.remove everything remains unchanged. I have 5 entities ( E1 - E5 ), referencing the entity ( E6 ) in question like this: @Entity public class EX { @OneToMany(mappedBy = "eX", fetch = FetchType.EAGER, cascade = { CascadeType.PERSIST, CascadeType.REMOVE }) private Set<E6> e6s; } E6 itself has the reverse @ManyToOne Relations:

Trigger calls in cascade deleting

ⅰ亾dé卋堺 提交于 2019-11-27 15:39:01
问题 I have table "A" in MySQL. It has some references with cascade deleting to some other tables ("B", "C", "D" ...). I need to use a trigger when something deletes from "A". This trigger works when I delete records from "A" directly. But it doesn't work with cascade deleting. Does any version of MySQL exist where my trigger will work with cascade deleting? Or, maybe, there is another way to call 回答1: From http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html Cascaded foreign key

PostgreSQL: FOREIGN KEY/ON DELETE CASCADE

主宰稳场 提交于 2019-11-27 15:36:50
问题 I have two tables like here: DROP TABLE IF EXISTS schemas.book; DROP TABLE IF EXISTS schemas.category; DROP SCHEMA IF EXISTS schemas; CREATE SCHEMA schemas; CREATE TABLE schemas.category ( id BIGSERIAL PRIMARY KEY, name VARCHAR NOT NULL, UNIQUE(name) ); CREATE TABLE schemas.book ( id BIGSERIAL PRIMARY KEY, published DATE NOT NULL, category_id BIGINT NOT NULL REFERENCES schemas.category ON DELETE CASCADE ON UPDATE CASCADE, author VARCHAR NOT NULL, name VARCHAR NOT NULL, UNIQUE(published,

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

江枫思渺然 提交于 2019-11-27 15:28:53
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 that they want to avoid - a cycle and multiple paths. A cycle would be where two tables have cascading

Nhibernate Cascade

好久不见. 提交于 2019-11-27 11:46:52
问题 What does Cascade in Nhibernate mean? I see a lot of options in cascading: Delete All AllDeleteOrphan DeleteOrphan SaveUpdate Can you explain these with with examples and their distinctions? 回答1: It means apply the action to an item's related items. Please see: NHibernate Cascades: the different between all, all-delete-orphans and save-update: none - do not do any cascades, let users handle them by themselves. save-update - when the object is saved/updated, check the associations and save

Should I use the CASCADE DELETE rule? [duplicate]

ぐ巨炮叔叔 提交于 2019-11-27 11:40:28
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)? 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 ORDER_LINES because clearly you want to delete this order, which consists of a header and some lines. On the

MySQL on delete cascade. Test Example

做~自己de王妃 提交于 2019-11-27 08:16:14
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 is automatically deleted d.If a row with id = 2 in table foo is deleted, all rows with foo_id = 2 in