MySQL on delete cascade. Test Example

Answer d. is correct, if and only if the storage engine actually supports and enforces foreign key constraints. If the tables are created with Engine=MyISAM, then neither b. or d. is correct. If the tables are created with Engine=InnoDB, then d. is correct. NOTE: This is true for InnoDB if and only if FOREIGN_KEY_CHECKS = … Read more

What is the difference between cascade & inverse in hibernate, what are they used for?

In case of many-to-many relation through intermediary table; “Cascade” says whether a record will be created/updated in the child table. Whereas “Inverse” says whether a record will be created/updated in the intermediary table e.g. Assume below scenario 1 student can have multiple phones. So Student class has property for Set of phones. Also 1 Phone … Read more

How do I use on delete cascade in mysql?

Here’s what you’d include in your components table. CREATE TABLE `components` ( `id` int(10) unsigned NOT NULL auto_increment, `typeId` int(10) unsigned NOT NULL, `moreInfo` VARCHAR(32), — etc PRIMARY KEY (`id`), KEY `type` (`typeId`) CONSTRAINT `myForeignKey` FOREIGN KEY (`typeId`) REFERENCES `types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) Just remember that you need to use … Read more

How does JPA orphanRemoval=true differ from the ON DELETE CASCADE DML clause

orphanRemoval has nothing to do with ON DELETE CASCADE. orphanRemoval is an entirely ORM-specific thing. It marks “child” entity to be removed when it’s no longer referenced from the “parent” entity, e.g. when you remove the child entity from the corresponding collection of the parent entity. ON DELETE CASCADE is a database-specific thing, it deletes … Read more