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
6
votes
2 answers

Hibernate cascade remove ConstraintViolationException

It seems the situation is simply (but it does not work). Db part (EVENT_ID is foreign key. FK_RR_E_CI constraint references on EVENT table) |-------| |----------------| | EVENT | 1 ------ ∞ | RECURRENT_RULE | |-------| …
Sergii
  • 7,044
  • 14
  • 58
  • 116
6
votes
1 answer

Cascading SQL select

I have a table of employees. Each employee row contains the employee's manager. One manager will have one or more employees and an employee may also be a manager. I'm trying to construct a query that will return ALL the employees of a given…
Brian P.
  • 206
  • 3
  • 14
6
votes
1 answer

@ManyToMany with cascade = CascadeType.REMOVE removes associations AND entities

I have 2 entities: Group and Grouped, with 1 ManyToMany association. In database, the Association table has a NOT NULL FK on both Group and Grouped. I want Hibernate to delete the association but not the group when all grouped are deleted. Code to…
Pleymor
  • 2,611
  • 1
  • 32
  • 44
6
votes
1 answer

Hibernate EntityManager: remove referenced entity not working

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…
dognose
  • 20,360
  • 9
  • 61
  • 107
6
votes
1 answer

nhibernate does not cascade delete children

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
6
votes
4 answers

Merge Primary Keys - Cascade Update

Is there a way to merge two primary keys into one and then cascade update all affected relationships? Here's the scenario: Customers (idCustomer int PK, Company varchar(50), etc) CustomerContacts (idCustomerContact int PK, idCustomer int FK, Name…
Chris Jackson
  • 540
  • 7
  • 16
6
votes
1 answer

Django on delete cascade not producing the right constraint in PostgreSQL

In Django, I have a model: class HmmInsectValue(models.Model): hmm = models.ForeignKey('HmmResult', on_delete=models.CASCADE) ... on a PostgreSQL database (9.3.2) this produces a constraint: FOREIGN KEY (hmm_id) REFERENCES…
gozzilli
  • 8,089
  • 11
  • 56
  • 87
6
votes
2 answers

ON DELETE CASCADE is not working is in sqlite3 in ios

I created a .sqlite file in ios programatically like below by enabling pragma foreignkeys ON NSFileManager *theFileManager = [NSFileManager defaultManager]; if ([theFileManager fileExistsAtPath:[self getDatabasePath]] == NO) { …
Karthik Mitta
  • 335
  • 3
  • 13
6
votes
1 answer

Hibernate, automatically persist dependant objects

I'm quite new to Hibernate and have been trying to determine what it will do for you and what it requires you to do. A big one is dealing with an object that has dependants that don't yet exist in the database. For example, I have a Project…
GordonM
  • 31,179
  • 15
  • 87
  • 129
6
votes
1 answer

JPA Cascade Persist Error

I have a One-to-Many relationship: A ProductCategory can contains many Product. This is the code: @Entity public class Product implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private String id; …
user477768
6
votes
2 answers

FOREIGN KEY references same table's column. Can't insert values

I created table with FOREIGN KEY and can't insert anything. CREATE TABLE menus ( id int(10), parent_id int(10), label varchar(255), PRIMARY KEY (id), FOREIGN KEY (parent_id) REFERENCES menus (id) ); I need FOREIGN KEY to automatically delete…
user1927652
  • 91
  • 1
  • 5
6
votes
2 answers

How can I make a cascade deletion in a one_to_many relationship in Rails ActiveRecord?

I have a model in rails with one_to_many relationship. When I delete the father, I'd like to delete all childrens. How should I do it? I want to delete all orders and its items when I delete a user My models are: class User < ActiveRecord::Base …
Daniel Cukier
  • 11,502
  • 15
  • 68
  • 123
6
votes
2 answers

No cascade insert for child with foreign key on parent

I have checked many posts on the internet and none address my problem. Really appreciate if anyone can help! I have OneToMany parent child relationship. Hibernate does not cascade insert child (Level2) when one of the child composite keys is the…
John
  • 61
  • 1
  • 1
  • 2
6
votes
3 answers

Java cascading JFrames

I have a class that extends javax.swing.JFrame built with NetBeans GUI editor. Is there a way to make this JFrame cascade when several of it being opened ?
Onca
  • 1,113
  • 3
  • 17
  • 31
6
votes
3 answers

Doctrine 2.1 - Relation Lost After ManyToMany Cascade Merge - Symfony2

After merging an entity that has related entities with relations set to cascade both persist and merge operations the relations are lost! Here are the entities: class Event implements NormalizableInterface { /** *…
matthew
  • 2,156
  • 5
  • 22
  • 38