Questions tagged [cascade]

Cascade refers to a table-definition keyword in relational databases; it instructs the query engine to take a certain action (delete, update), when a primary key is modified, on tables linked by a foreign key.

Cascade is a keyword that helps define the behavior of database tables linked by a foreign key, when the primary table is changed. If cascade is specified in the table definition, then, for example:

  • if a row in the primary table is deleted, the corresponding rows in the linked table can be deleted
  • if a primary key is updated, then the corresponding rows can be updated
1381 questions
7
votes
1 answer

Cascading collections using NHibernate StatelessSession

What is the proper way to bulk insert entities which contain collections of other entities (a HasMany mapping), using stateless sessions? E.g. Parent class is mapped like this: class ParentMap : ClassMap { public ParentMap() { …
vgru
  • 49,838
  • 16
  • 120
  • 201
7
votes
1 answer

MySql cascade delete from 2 tables

I have a MySql schema which uses class table inheritance, but I want the child tables to have cascade delete from the parent table, and a foreign table. create table parent ( _key bigint unsigned not null, name varchar(64) unique not null, …
JSarwer
  • 313
  • 2
  • 16
7
votes
2 answers

Hibernate: Delete all children with one query

TL;DR: Is it possible to configure Hibernate to delete all child objects using a single delete query? Full Question: I have the following parent/child association defined in Hibernate 5.1: public class Parent { @OneToMany(fetch = FetchType.EAGER,…
Adam Parod
  • 178
  • 1
  • 10
7
votes
3 answers

SQL Server - Cascading DELETE with Recursive Foreign Keys

I've spent a good amount of time trying to figure out how to implement a CASCADE ON DELETE for recursive primary keys on SQL Server for some time now. I've read about triggers, creating temporary tables, etc but have yet to find an answer that will…
7
votes
1 answer

How to make cascade version set in maven?

I have multimodule maven project and want to automate part of release preparing. Before release I increase the version of changed module A, and because I have module B depends on A, I also need to increase version of B. I know that there is…
mulya
  • 1,273
  • 13
  • 26
7
votes
2 answers

T-SQL: DROP Table cascade constraints equivalent?

In oracle, I can issue a DROP TABLE ... cascade constraints and it won't complain about FKs, etc. Is there an equivalent in T-SQL?
chris
  • 36,094
  • 53
  • 157
  • 237
7
votes
4 answers

what happens to the last return *this c++?

Time &Time::setHour( int h ) { hour = ( h >= 0 && h < 24 ) ? h : 0; return *this; } Time &Time::setMinute( int m ) { minute = ( m >= 0 && m < 60 ) ? m : 0; return *this; } Time &Time::setSecond( int s )…
user3348712
  • 161
  • 10
7
votes
3 answers

Ef code first complicate cascade delete scenario

I have this scenario: I have these classes: public class A { public int Id {get;set;} public virtual ICollection bCollection {get; set; } } public class B { public int Id {get;set;} } public class C1 : BaseClass1 { public int…
ilay zeidman
  • 2,654
  • 5
  • 23
  • 45
7
votes
3 answers

ON DELETE CASCADE option not in generated when using ddl schema generation on Mysql

In a Maven-Spring-Hibernate-MySql running on Tomcat web app I'm using hibernate ddl to generate my DB schema with MySQL5InnoDBDialect. The schema is generated just fine except the cascade option for foreign-keys. For example I have this structure: A…
forhas
  • 11,551
  • 21
  • 77
  • 111
7
votes
6 answers

Delete rows from two tables in one query

I have two tables: orders and orders_items. Both sharing the field orderID. I want to delete all rows from both tables where orderID=500, but I need to do this in only one query. Is this possible?
The Disintegrator
  • 4,147
  • 9
  • 35
  • 43
7
votes
2 answers

Cascade delete on many-to-many between same table

I'm trying to create a many-to-many relation between the same table in SQL Server. I have one table Object with columns ObjectId and Name. The relation follows these rules: a child can have many parents a parent can have many children ObjectA…
user1793963
  • 1,295
  • 2
  • 12
  • 24
6
votes
0 answers

Entity Framework cascade delete parent row in self-referenced table

In my MS SQL Server 2008 database I have self-referenced table with categories for hierarchy (ID and ParentID). Table have a self Foreign Key constraint and "Instead of Delete" trigger to perform deleting the full node with its children. To manage…
Korj
  • 61
  • 3
6
votes
2 answers
6
votes
2 answers

How to do a cascade save in hibernate

I have objects A and B. Object A is like class A{ Set } Now when I save A I want that all objects in Set of A should be automatically saved in DB. How can I do it?
akshay
  • 5,235
  • 14
  • 39
  • 49
6
votes
3 answers

Hibernate Many-to-Many with join-class Cascading issue

I have a Many-to-Many relationship between the class Foo and Bar. Because I want to have additional information on the helper table, I had to make a helper class FooBar as explained here: The best way to map a many-to-many association with extra…
kscherrer
  • 5,486
  • 2
  • 19
  • 59