cascading-deletes

Code first causing required relation to be optional?

ぐ巨炮叔叔 提交于 2019-12-23 09:01:05
问题 public class Client { public Int32 ClientID { get; set; } public virtual ICollection<Inquiry> InquiryManufacturers { get; set; } public virtual ICollection<Product> Products { get; set; } public virtual ICollection<Inquiry> InquiryRetailers { get; set; } } public class Product { public Int32 ProductID { get; set; } public Int32 ClientID { get; set; } public virtual Client Client { get; set; } public virtual ICollection<Inquiry> Inquiries { get; set; } } public class Inquiry { public Int32

Problem creating foreign keys in mySql

点点圈 提交于 2019-12-23 02:54:15
问题 I created a foreign key in my sql by the following statemnt.. ALTER TABLE `users` ADD FOREIGN KEY ( `id`) REFERENCES `user_login` (`user_id`) ON DELETE CASCADE ; The creation appears to succeed then after that I execute a delete statement DELETE From user_login WHERE user_id = 1576; yet in users the row still exists that is referencing that. I open up the mysql workbench and it doesn't show any signs that the foreign key was created. Does anyone know why this would be? Or what I am doing

Oracle Delete Statement: how many rows have been deleted by cascade delete

末鹿安然 提交于 2019-12-22 23:24:09
问题 I'm executing a statement like DELETE FROM USER WHERE USER_ID=1; In SQLDeveloper. As the user is referenced in many tables (for example the user has an order, settings, ...) we activated ON DELETE CASCADE so that we do not have to delete each and every row manually. However while developing we are interested to know how many rows and and in which tables are "automatically" deleted by cascade delete. Is there any way to find this out. Either by SQL-Statement, directly in sqldeveloper from a

Entity Framework cascading delete problems - Foreign key set to null

丶灬走出姿态 提交于 2019-12-22 14:03:08
问题 I have the following Model which I mapped with the Entity Framework: Mitglied -> Auftrag -> Teilprojekt I have set up everything in the database with foreign keys and "on delete cascade". If I perform some tests on the database everything works fine. The problem arises as soon as I use the Entity Framework to add and especially delete objects. Consider the following code: Mitglieder m1 = new Mitglieder(); m1.Name = "erstes"; Auftraege a1 = new Auftraege(); a1.Name = "a1"; m1.Auftraege.Add(a1)

nhibernate does not cascade delete children

时间秒杀一切 提交于 2019-12-22 05:15:14
问题 The scenario is as follows, I have 3 objects (i simplified the names) named Parent, parent's child & child's child parent's child is a set in parent, and child's child is a set in child. mapping is as follows (relevant parts) parent <set name="parentset" table="pc-table" lazy="false" fetch="subselect" cascade="all-delete-orphan" inverse="true"> <key column=FK_ID_PC" on-delete="cascade"/> <one-to-many class="parentchild,parentchild-ns"/> </set> parent's child <set name="childset" table="cc

Grails - multiple belongsTo of same class with cascading deletion

▼魔方 西西 提交于 2019-12-22 04:36:17
问题 This one is for the Grails users here. I asked it on the grails - user mailing list, but I figured since I've been fighting this for a couple of days I should cast as wide a net as possible. I'm having some difficulty with trying to model relationships between two objects of the same type in another object (different type) referencing the two objects. As an example of what I'm trying to do, suppose you're modeling relationships among family members. Any given relationship "belongsTo" two

How to find if a referenced object can be deleted?

纵然是瞬间 提交于 2019-12-22 04:07:46
问题 I have an object called "Customer" which will be used in the other tables as foreign keys. The problem is that I want to know if a "Customer" can be deleted (ie, it is not being referenced in any other tables). Is this possible with Nhibernate? 回答1: What you are asking is to find the existence of the Customer PK value in the referenced tables FK column. There are many ways you can go about this: as kgiannakakis noted, try to do the delete and if an exception is thrown rollback. Effective but

How to enforce referential integrity on Single Table Inheritance?

半腔热情 提交于 2019-12-22 02:34:33
问题 I've read some of Bill Karwin's answers about single table inheritance and think this approach would be good for the setup I am considering: Playlist -------- id AUTO_INCREMENT title TeamPlaylist ------------ id REFERENCES Playlist.id teamId REFERENCES Team.id UserPlaylist ------------ id REFERENCES Playlist.id userId REFERENCES User.id PlaylistVideo ------------- id playlistId REFERENCES Playlist.id videoId REFERENCES Video.id All the CASCADE options are set to DELETE which will work

Should I let JPA or the database cascade deletions?

安稳与你 提交于 2019-12-20 12:15:42
问题 Let's say we have two entities, A and B. B has a many-to-one relationship to A like follows: @Entity public class A { @OneToMany(mappedBy="a_id") private List<B> children; } @Entity public class B { private String data; } Now, I want to delete the A object and cascade the deletions to all its children (B). There are two ways to do this: 1) Add cascade=CascadeType.ALL, orphanRemoval=true to the OneToMany annotation, letting JPA remove all children before removing the A-object from the database

My 'ON DELETE CASCADE ' does not work

本小妞迷上赌 提交于 2019-12-20 04:51:31
问题 I have got 3 tables: lt_hdefaults , lt_hperiods and lt_hrules . In lt_hdefaults , there is one row for a property for a particular year. In the lt_hperiods table, there could be more than one period, call them seasons. In the lt_hrules table, there could be more than one rule for each period. Now, what I could not make work: when the user deletes a record from lt_hdefaults , other data related to the deleted record should be removed from lt_hperiods and lt_hrules table. I am trying to achieve