Cascade

Delete rows from two tables

喜你入骨 提交于 2020-01-05 08:26:10
问题 I have two tables. Those tables have two relation between them. Table 1 * ID_XPTO (PK) * Detail Table 2 * ID_XPTO (FK) (PK) * ID_XPTO2 (FK) (PK) Those two relations exists. Table 1 -< Table2 Table 1 -< Table2 My question is that I need to delete some row in table 1. I'm currently doing, declare @table Table (xptoTable2 int) insert into @table select ID_XPTO2 from Table2 where ID_XPTO = @ID_XPTO delete from Table2 where ID_XPTO = @ID_XPTO delete from Table where ID_XPTO in (select

SQLite FOREIGN KEY ON DELETE CASCADE not working

旧时模样 提交于 2020-01-05 07:01:09
问题 I'm running the following script, wtf.sql , on SQLite Version 3.16.0: PRAGMA foreign_keys = ON; CREATE TABLE 'ZIP'( 'Zip' INTEGER PRIMARY KEY NOT NULL, 'City' TEXT NOT NULL, 'State' TEXT NOT NULL ); CREATE TABLE 'ADDRESS'( 'Address_id' INTEGER PRIMARY KEY AUTOINCREMENT, 'Line_1' TEXT NOT NULL, 'Line_2' TEXT, 'Zip' INTEGER NOT NULL, FOREIGN KEY('Zip') REFERENCES ZIP('Zip') ON DELETE CASCADE ); INSERT OR IGNORE INTO ZIP('Zip','City','State') VALUES ('90210','Beverly Hills','CA') ; INSERT INTO

Modify entity with EntityListener on cascade

大兔子大兔子 提交于 2020-01-05 05:18:51
问题 I have a database in which an entity (say, User) has a list of entities (say, List). As a requirement, I must have a denormalized count of the entities on the list: @Entity class User { /* ... */ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private List<Friendship> friends; public int friendsCount; /* ... */ } When I add a new element to the list, I must, transactionally, increase the corresponding counter. I tried to do so using an EntityListener: class

How to cascade delete entities with unidirectional 'ManyToOne' relationship with JPA

穿精又带淫゛_ 提交于 2020-01-04 04:15:12
问题 I have two entity classes 'User' and 'Department' with unidirectional 'ManyToOne' relationship as below. public class User{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "DEPARTMENT_ID", nullable = true) private Department department; } public class Department{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; } If I want to delete some users and cascade remove the

NHibernate Definitive Cascade application guide

霸气de小男生 提交于 2019-12-31 07:57:26
问题 Are there any internet resources that have a definitive guide to all of the cascade settings for NHibernate that will include examples of the class structure, HBM and the implications of actions with each of the cascade settings for all of the relationships with NH. Also it would be helpful if there were examples for common associations to be done in the most correct manner such as setting up a states table that you will never end up cascade deleting a state, or that deleting an object that

NHibernate Definitive Cascade application guide

牧云@^-^@ 提交于 2019-12-31 07:57:14
问题 Are there any internet resources that have a definitive guide to all of the cascade settings for NHibernate that will include examples of the class structure, HBM and the implications of actions with each of the cascade settings for all of the relationships with NH. Also it would be helpful if there were examples for common associations to be done in the most correct manner such as setting up a states table that you will never end up cascade deleting a state, or that deleting an object that

JPA: Cascade remove does not delete child

99封情书 提交于 2019-12-30 23:43:10
问题 Edit: Modifying the question to better reflect the problem. Originally posted question here I have a parent ( Context ) and a child ( User ) entity (ManyToOne relationship). Cascade 'REMOVE' on the parent is not deleting the child. Code as below: //Owning side - child @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @Column(name = DBColumns.USER_NAME) private String name; @ManyToOne @JoinColumn(name = DBColumns.CONTEXT_ID) private Context context

Hibernate OneToOne lazy loading and cascading

落爺英雄遲暮 提交于 2019-12-30 04:41:07
问题 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 update and delete has to be translated into DDL class Parent @OneToOne(mappedBy = "parent", cascade = CascadeType.ALL) public Child getChild() class Child @OneToOne(fetch = FetchType.LAZY) @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name=

How to properly cascade delete managed objects in Core Data?

一曲冷凌霜 提交于 2019-12-30 03:56:22
问题 I have a Core Data model which has three entities: A, B, and C. A has a one-to-many relationship with B, and B has a many-to-many relationship with C. The delete rule for A -> B is "Cascade", and B -> A is "No Action". The delete rule for B -> C is "No Action", and C -> B is "Deny". I am having trouble performing a delete on the A entity. What I want to happen is the following: I delete an instance of A (using deleteObject: ) The delete propagates to any B's associated with A (due to the

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

旧街凉风 提交于 2019-12-28 16:02:48
问题 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 Anamnesis Anamnesis { get; set; } . . . } public class Anamnesis { [Key, ForeignKey("Student")] public int AnamnesisId { get; set; } public virtual Student Student { get; set; } . . . } where, Student is the principal entity and Anamnesis it the entity that