Questions tagged [cascading-deletes]

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row.

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row. The deletion is performed recursively and enabled with the ON DELETE CASCADE property of the foreign key.

587 questions
5
votes
1 answer

JPA relationship not getting updated when children are removed

Given the following scenario: @Entity public class A { @OneToMany(mappedBy = "a", cascade = CascadeType.ALL) private List bList; } @Entity public class B { @ManyToOne() @JoinColumn(name = "a_id", referencedColumnName = "id") private A…
Rasmus Franke
  • 4,434
  • 8
  • 45
  • 62
5
votes
1 answer

Hibernate Cascading Delete Not working as expected

I am using hibernate 3 and attempting to delete a record in the database, and the delete is not working as I would expect. The schema hibernate is working against (in pseudocode): create table Employer( employer_id number(12) primary key, …
BuffaloBuffalo
  • 7,703
  • 4
  • 28
  • 29
5
votes
1 answer

SQL Server 2008 - Multiple Cascading FK's - Do i need a trigger?

I have a 1..* relationship between User and Post. (one user has many posts) Post has a FK called "UserId", which maps to the "UserId" field on User table. I tried to set this FK as Cascade UPDATE/DELETE, but i get this error: 'Users' table saved…
RPM1984
  • 72,246
  • 58
  • 225
  • 350
5
votes
3 answers

C# - Predict file system events on folder delete

This is more a question about what's the best practice in implementing this. I have a FileSystemWatcher which should inform me about User's changes on files and folders. Also subdirs are watched. In the same directory my program does also sometimes…
fpdragon
  • 1,867
  • 4
  • 25
  • 36
5
votes
1 answer

Does Grails cascade deletes when not using domain.delete()?

From the Grails site: http://www.grails.org/doc/1.0.x/guide/5.%20Object%20Relational%20Mapping%20(GORM).html class Airport { String name static hasMany = [flights:Flight] } class Flight { String number static belongsTo =…
Igor
  • 33,276
  • 14
  • 79
  • 112
5
votes
2 answers

Hibernate delete objects on cascade

I'm sligthly confused as to how the cascade="delete" works. I defined the mapping in the following way in the City mapping file:
sass
  • 309
  • 2
  • 8
  • 20
5
votes
2 answers

Realm "cascade delete" on Android

I did the search about "cascade delete" operation for the Realm. Sadly that feature has not been implemented yet. I made my own implementation of it and shared it here. How to make generic code for the Realm "cascade delete" operation ?
5
votes
1 answer

sql cascading deletes

I have a question about cascading deletes and foreign key references: Let's assume the following tables: ITEMX | ITEMY ------------------ | ------------ ID FKID_ITEMY | ID 1 1 | 1 2 1 …
Jason
  • 741
  • 1
  • 7
  • 7
5
votes
1 answer

Why does a manually defined Spring Data JPA delete query not trigger cascades?

I have following problem: when I try to delete an entity that has following relation: @OneToMany(mappedBy="pricingScheme", cascade=CascadeType.ALL, orphanRemoval=true) private Collection chargeableElements; with a CrudRepository…
Piotr Tempes
  • 1,091
  • 1
  • 12
  • 26
5
votes
2 answers

[MySQL]: DELETE rows from two dependent tables

I am attempting to delete all rows in two dependent tables based on a third tables ID. Table structure: Transaction -Transaction_ID (primary) -Timestamp Purchase -Item_ID -Transaction_ID -Purchase_ID (primary) Item -Item_ID (primary) -Client_ID I…
Derek Adair
  • 21,846
  • 31
  • 97
  • 134
5
votes
3 answers

"On Delete Cascade" if deleting a row from the child table

I'm having a difficult time understanding "on delete cascade" If I had the following example: create table X (id int primary key, name char(10)); create table Y (bid int primary key, aid references A(id) on delete cascade); X contains one row (111,…
5
votes
3 answers

sql server, cascade delete and parent/child table

i have one simple table with following columns: id, name and parentID i created relationship diagram between id and parentID (on a same table), like simple tree, on the same table, but when i tried to user cascade delete it was disabled for me i…
Sasha
  • 20,424
  • 9
  • 40
  • 57
5
votes
1 answer

How to DELETE without ON DELETE CASCADE (conflict REFERENCE constraint)

I have a gigantic legacy database with a table that has multiple foreign keys pointing to one other table and with not a single cascade in sight, similar to sample tables below: create table Users ( Id int primary key identity, Name…
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
5
votes
1 answer

Deleting from two h2 tables with a foreign key

I have an h2 database with two tables with foreign keys like CREATE TABLE master (masterId INT PRIMARY KEY, slaveId INT); CREATE TABLE slave (slaveId INT PRIMARY KEY, something INT, CONSTRAINT fk FOREIGN KEY (slaveId) REFERENCES…
maaartinus
  • 44,714
  • 32
  • 161
  • 320
5
votes
1 answer

Grails (GORM) Many-To-One Cascade Delete Behaviour

I've been struggling to produce the right configurations to produce cascade-delete behaviour in a relatively simple Grails project. Say I have the following simple domain classes: class Author { String name static constraints = { …
Glennn
  • 467
  • 1
  • 7
  • 18