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
9
votes
3 answers

Hibernate: Clean collection's 2nd level cache while cascade delete items

I have a problem Hibernate does not update 2nd level cache for a collection of items which are subject of cascade removal. Details Assume we have an object Parent which has Parent.myChildren collection of Child objects. Now we have also object…
Yurii Soldak
  • 1,458
  • 4
  • 19
  • 24
9
votes
4 answers

Two foreign keys reference one table - ON UPDATE SET NULL doesn't work

I've got two foreign keys in a table. Let's assume that table is called News and has foreign keys updatedById and createdById, both of which point to userId in table Users. Now I want to set to NULL foreign keys when user is deleted, but when I try…
Wojciech Kulik
  • 7,823
  • 6
  • 41
  • 67
8
votes
2 answers

JPA: implicit cascades for relationships mapped as @ManyToMany @JoinTable?

I have the following mapping: @Entity @Table(name = "Prequalifications") public class Prequalification implements Serializable { ... @ManyToMany @JoinTable(name = "Partnerships", joinColumns = @JoinColumn(name = "prequalification_id",…
Kawu
  • 13,647
  • 34
  • 123
  • 195
8
votes
2 answers

Hibernate Cascade PERSIST

I have a general question about Hibernate that I'm batteling with. I have class A and class B, where B is dependent on A In my code when I call em.persist(objOfTypeA) I would expect the insert to go and insert into both tables AAA and BBB. If I…
WonkeyDonkey
  • 119
  • 1
  • 1
  • 5
8
votes
1 answer

Entity Framework Code first - FOREIGN KEY constraint problem

I'm new to EF code first principal and currently with no clue what to do.. I have 2 POCO classes.. public class Problem { public int ProblemID { get; set; } public int UserID { get; set; } public int CategoryID { get; set; } public…
rjovic
  • 1,207
  • 2
  • 16
  • 37
8
votes
2 answers

How to solve TypeError: on_delete must be callable on Django models?

Suddenly I am getting an error saying TypeError: on_delete must be callable. I don't know how to solve this error as I don't see field=models.ForeignKey(default=1, on_delete='CASCADE', to='main.Category'), mentioned anywhere in my code. File…
GTA.sprx
  • 817
  • 1
  • 8
  • 24
8
votes
1 answer

Dynamically load cascading Questions in Android View

We are currently working on project where a web user creates a survey which has cascading questions (cascading means questions that have few answers and depend on those answers rest of the questions changes) and then mobile users should get this…
Selaka Nanayakkara
  • 3,296
  • 1
  • 22
  • 42
8
votes
4 answers

Deleting from table with @OneToOne annotation

I'm using JPA2 and Hibernate implementation. I've got simple mapping like this: @Entity class Topic { @Id @GeneratedValue(strategy = IDENTITY) int id; @OneToOne(cascade = ALL) @JoinColumn(name = "id_poll") private Poll…
Dawid
  • 644
  • 1
  • 14
  • 30
8
votes
1 answer

JPA and Hibernate Cascade DELETE OneToMany does not work

I've been reading post after post and article after article trying to get cascade deletes to work with JPA/Hibernate in the latest Spring Boot version. I've read that You have to use Hibernate specific cascades and I've read that you don't. I've…
Gregg
  • 34,973
  • 19
  • 109
  • 214
8
votes
5 answers

Django: merging objects

I have such model: class Place(models.Model): name = models.CharField(max_length=80, db_index=True) city = models.ForeignKey(City) address = models.CharField(max_length=255, db_index=True) # and so on Since I'm importing them from…
Valentin Golev
  • 9,965
  • 10
  • 60
  • 84
8
votes
1 answer

PostgreSQL 'Deferrable Delete' still hits constraint on Delete

I want to delete rows from two tables which have a dependence upon each other through a set of deferrable constraints. To simplify this post, I've mocked up a simple DB schema. I'm hoping to remove entries from some table, 'delete_from_me', inside a…
heymatthew
  • 6,716
  • 5
  • 26
  • 22
7
votes
1 answer

NHibernate, "On Delete Cascade", cascade deleting rows in related tables?

I've been using NHibernate (with Fluent-NHibernate mappings) in a project for the first time over the last few weeks, all was going well until today when I've hit a problem (most probably my own error). I've made a small sample to illustrate what…
7
votes
4 answers

Hibernate OneToOne lazy loading and cascading

Here's what I'm trying to do. Create a parent with a OneToOne relation to a child The parent has to fetch the children using lazy loading If parent is removed, so is the child If the child is removed, the parent should not be affected The cascade…
Holm
  • 982
  • 2
  • 12
  • 20
7
votes
2 answers

Cascade Delete Rule in EF 4.1 Code First when using Shared Primary Key Association

I implemented a bidirectional 1:1 relationship based on this answer: Primary /Foreign Key in Entity Framework I define the bidirectional relation this way: public class Student { public virtual int StudentId { get; set; } public virtual…
7
votes
2 answers

ON DELETE CASCADE for multiple foreign keys with Sequelize

Suppose I have three models: Task: A thing that needs done, like "take out the recycling". Can be done many times. TaskList: An object that represents a list of tasks, and has its own metadata. TaskListEntry: An association between Task and…
Brad
  • 159,648
  • 54
  • 349
  • 530