Cascade

Cascade delete on many-to-many between same table

 ̄綄美尐妖づ 提交于 2019-12-04 04:16:05
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 can be a child of ObjectB and ObjectB can be a child of ObjectA but an object cannot be a direct child of itself So I create a second table ObjectRelation with columns ParentId and ChildId and of course I want these relations to be deleted by cascade. But when I try this in SQL Server I get the error Introducing FOREIGN KEY constraint 'FK_ObjectRelation

tsql script to add delete cascade to existing tables

泪湿孤枕 提交于 2019-12-04 01:46:52
is there a script that can be used to enable cascaded deletion for existing tables. Thanks. VMAtm ALTER TABLE [wm].[TABLE_NAME] WITH NOCHECK ADD CONSTRAINT [FK_TABLE_NAME_PARENT_TABLE_NAME] FOREIGN KEY([FOREIGN_KEY]) REFERENCES [wm].[PARENT_TABLE_NAME] ([PRIVATE_KEY]) ON DELETE CASCADE GO TABLE_NAME : name of the table where the children are stored. PARENT_TABLE_NAME : name of the table where the parents are stored. This placeholders can be equal FK_TABLE_NAME_PARENT_TABLE_NAME : just name for the constraint FOREIGN_KEY : field in the child table for the connection with the parents, for

What Does Rails Do With Both :dependent => :destroy and cascade delete/nullify/restrict

狂风中的少年 提交于 2019-12-04 00:22:22
I'm trying to decide how best to set up (if at all) foreign key constraints for my rails application. I have a model Response that belongs_to a Prompt . I would like to use :dependent => :destroy to have destroy called on every Response that belongs to a deleted Prompt and I'm trying to decide what delete constraint I should place on my foreign key. In short I want advice about how I can get best take advantage of both the destroy method on dependent objects and foreign key constraints to ensure cruft doesn't accumulate and reflect the logical structure of the data being stored. Several

Hibernate - One to many relationship and orphanRemoval cascade

北城以北 提交于 2019-12-03 13:28:57
I have a basic one to many relation parent / child like in the chapter 21 of Hibernate references book. The cascade is only from child to parent (persist cascade only because I don't want to delete the parent if I delete a child). When I add a child to the parent and I save the child, I have a TransientObjectException... @Entity public class Parent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(mappedBy = "parent", orphanRemoval = true) private List<Child> childs; public List<Child> getChilds() { return childs; } public void setChilds

Entity Framework Code first - FOREIGN KEY constraint problem

霸气de小男生 提交于 2019-12-03 12:49:17
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 int RatingID { get; set; } public string Title { get; set; } public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public int State { get; set; } public DateTime CreatedOn { get; set; } public virtual Rating Rating { get; set; } public virtual Category Category { get; set; } public virtual User User { get;

Deletions in a many-to-many structure

不羁岁月 提交于 2019-12-03 10:47:14
I just want to check really quickly. Say I have two entities in a data model: Catalog, and Product. They have a many-to-many relationship with each other, and both are required (a Catalog must have at least one Product, and all Products must each belong to at least one Catalog). So if I was to delete a Product, its deletion should be Nullify, of course. But what should the deletion policy be for Catalog? If a Catalog is deleted, not all of its Products necessarily exclusively belong to it. A Product may belong to more than one Catalog. So I definitely shouldn't use Cascade. However, is Nullify

Hibernate: OneToMany save children by cascade

走远了吗. 提交于 2019-12-03 08:40:42
问题 In the class Parent there is a list List. When the parent is saved the children which have been added or changed shall be save / updated by hibernate. I've found many explanations on this, however, I just don't get it to work. Parent.class try A @Entity public class Parent { // id and other attributes @OneToMany(mappedBy = "parent") @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.ALL) protected List<child> children; Parent.class try B @Entity public class Parent { //

Django: merging objects

♀尐吖头ヾ 提交于 2019-12-03 07:54:26
问题 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 many sources, and users of my website are able to add new Places, I need a way to merge them from an admin interface. Problem is, name is not very reliable since they can be spelled in many different ways, etc I'm used to use something like this: class Place(models

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

吃可爱长大的小学妹 提交于 2019-12-03 06:59:14
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 Humans with Humans.myAllHumans collection and all Parent and Child objects are in that collection. Now we session.delete(parent) and all the children are cascade removed from the database, but Humans.myAllHumans collection's cache is not updated! It still assumes that cascade deleted objects are in database and we hit following exception while trying to

【转载】Hibernate3注解

孤街浪徒 提交于 2019-12-03 04:15:11
Hibernate3注解 收藏 1、@Entity(name="EntityName") 必须,name为可选,对应数据库中一的个表 2、@Table(name="",catalog="",schema="") 可选,通常和@Entity配合使用,只能标注在实体的class定义处,表示实体对应的数据库表的信息 name:可选,表示表的名称.默认地,表名和实体名称一致,只有在不一致的情况下才需要指定表名 catalog:可选,表示Catalog名称,默认为Catalog(""). schema:可选,表示Schema名称,默认为Schema(""). 3、 @id 必须 @id定义了映射到数据库表的主键的属性,一个实体只能有一个属性被映射为主键.置于getXxxx()前. 4、@GeneratedValue(strategy=GenerationType,generator="") 可选 strategy:表示主键生成策略,有AUTO,INDENTITY,SEQUENCE 和 TABLE 4种,分别表示让ORM框架自动选择, 根据数据库的Identity字段生成,根据数据库表的Sequence字段生成,以有根据一个额外的表生成主键,默认为AUTO generator:表示主键生成器的名称,这个属性通常和ORM框架相关,例如,Hibernate可以指定uuid等主键生成方式. 示例: