Cascade

Unidirectional association with WillCascadeOnDelete

时光怂恿深爱的人放手 提交于 2019-12-10 10:49:10
问题 I have a very simple unidirectional class mappings. public class MyDbContext : DbContext { public MyDbContext() : base("CodeFirstDatabase") { } public DbSet<Contact> Contacts { get; set; } public DbSet<PhoneNumber> Number { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); modelBuilder.Entity<Contact>() .HasMany(c => c.Numbers)

Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

放肆的年华 提交于 2019-12-10 10:03:25
问题 class Owner { static hasMany = Dog } class Sitter { static hasMany = Dog } class Dog { static belongsTo = [Owner, Sitter] } My question is: If I create a Dog instance D, a Owner instance O, a Sitter instance S and associate D with both O and S, what happens to O when S gets deleted? Would O still have D? Since it's a cascade-delete, both S and D would get deleted, right? When what happens to O? Would it still have D? 回答1: I have tested it, it follows the cascade rule: if you delete Owner, Dog

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

ε祈祈猫儿з 提交于 2019-12-10 04:34:05
问题 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 children when parent was deleted. This table was successfully created but I can't insert anything. INSERT INTO `menus` (`parent_id`, `label`) VALUES ('1', 'label1'); or INSERT INTO `menus` (`label`) VALUES ( 'label1'); #1452 - Cannot add or update a child

Hibernate doesn't generate cascade

半城伤御伤魂 提交于 2019-12-10 03:34:15
问题 I have a set hibernate.hbm2ddl.auto to create so that Hibernate creates the tables in mysql for me. However, it doesn't seem that hibernate correctly adds Cascade on the references in the table. It does however work when I for instance delete a row, and I have a delete cascade as hibernate annotation . So I guess that means that Hibernate reads the annoation on runtime, and perform cascading manually? Is that normal behavior? For instance: @Entity class Report { @OneToOne(cascade =

PreUpdate cascade entity persist symfony 2.3

試著忘記壹切 提交于 2019-12-09 21:56:20
问题 I have a bit of problems with PreUpdate HasLifecycleCallbacks. I have an entity, let say "A" with have a OneToOne relation with the entity "B". So I have: /** * @ORM\Entity() * @ORM\HasLifecycleCallbacks */ class A { /** * @ORM\OneToOne(targetEntity="B", inversedBy="attrA", cascade={"persist", "remove"}) * @ORM\JoinColumn(name="fieldB", referencedColumnName="id") */ private $attrB; public function __construct() { $this->attrB = new B(); } /** * @ORM\PrePersist * @ORM\PreUpdate */ public

Hibernate - One to many relationship and orphanRemoval cascade

五迷三道 提交于 2019-12-09 11:39:50
问题 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 =

Deletions in a many-to-many structure

ⅰ亾dé卋堺 提交于 2019-12-09 07:48:54
问题 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

CASCADE DELETE on two foreign key constraints

自古美人都是妖i 提交于 2019-12-09 05:50:56
问题 I have the following example: Table A -some_id Table B -another_id Table C -some_id_fk -another_id_fk I want to cascade a row on Table C if both some_id and another_id are deleted from their respective tables. How can I make a row in Table C cascade itself when two foreign keys are deleted? If only one of the FKs is deleted, the affected row should change to a null value in the column referencing that foreign key. 回答1: I suggest two foreign key constraints with ON DELETE SET NULL and a

how to implement chained select using Mysql Php and query

社会主义新天地 提交于 2019-12-08 14:42:32
问题 How can I add a third drop down to this code. I have not been able to figure it out. Thanks!!! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript" src="jqueryui/js/jquery-ui-1.8.15.custom.min.js"></script> <script type="text/javascript" src="jqueryui/js/jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("select#category").change(function(){ var id = $(

Hibernate NullPointer on INSERTED id when persisting three levels using @Embeddable and cascade

前提是你 提交于 2019-12-08 13:44:48
问题 I cannot cascade merge with persist three levels of entities using @EmbeddedId in the last entity. I have three following entities: 1. Voucher 2. Rate 3. RatePerChannelOverwrite The Voucher is fetched by a service. Then I want to add new Rate to the voucher. Then I want to add new RatePerChannelOverwrite to the Rate . So both Rate and RatePerChannelOverwrite will have their @Id as NULL. This is working. However later I tried to split RatePerChannelOverwrite into two classes and have: