cascading-deletes

Hibernate Cascading Delete Not working as expected

倾然丶 夕夏残阳落幕 提交于 2019-12-07 05:28:37
问题 I am using hibernate 3 and attempting to delete a record in the database, and the delete is not working as I would expect. The schema hibernate is working against (in pseudocode): create table Employer( employer_id number(12) primary key, employer_name varchar2(50) ); create table Employee( employee_id number(12) primary key, employee_name varchar2(50), employer_id number(12) foreign key references employer.employer_id not null ); create table Employee_Roles( role_id number(12) primary key,

Figure out if a table has a DELETE on CASCADE

与世无争的帅哥 提交于 2019-12-06 17:14:12
问题 Can I know if a database have DELETE ON CASCADE with a query? 回答1: Yes. Just query the INFORMATION_SCHEMA SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS Or more specifically -- This query will list all constraints, their delete rule, -- the constraint table/column list, and the referenced table SELECT r.CONSTRAINT_NAME, r.DELETE_RULE, r.TABLE_NAME, GROUP_CONCAT(k.COLUMN_NAME SEPARATOR ', ') AS `constraint columns`, r.REFERENCED_TABLE_NAME FROM information_schema.REFERENTIAL

Why does a manually defined Spring Data JPA delete query not trigger cascades?

邮差的信 提交于 2019-12-06 14:43:50
问题 I have following problem: when I try to delete an entity that has following relation: @OneToMany(mappedBy="pricingScheme", cascade=CascadeType.ALL, orphanRemoval=true) private Collection<ChargeableElement> chargeableElements; with a CrudRepository through a provided delete method it removes the entity along with its all chargeable elements which is fine. The problem appears when I try to use my custom delete: @Modifying @Query("DELETE FROM PricingScheme p WHERE p.listkeyId = :listkeyId") void

Hibernate @OnDelete cascade same table

折月煮酒 提交于 2019-12-06 13:44:29
I am trying to create a table which captures parent child relationships, like a tree. I would like to maintain only two columns to capture this structure "id" and "parent". I want the database to be able to cascade delete all children when a row is deleted. Below is the Hibernate Entity that I have created, I have added the annotation @OnDelete(action = OnDeleteAction.CASCADE) however, the ON DELETE CASCADE is not added to the table when the table is created by Hibernate. Is this a bug? Or is there something I am missing or not understanding? @Entity public class Tree { @Id @Column(name = "id"

Delete an item from many-to-many relationship

纵然是瞬间 提交于 2019-12-06 13:02:36
I've following mapping for two tables having a Many-to-Many relationship between them. How do I delete an entry from the mapping table, which is 'TB_EMAIL_GRUPO_ARQUIVO' in my case? I just need to delete the data from this "joining" table and I don´t need to delete it from the "parent tables". GrupoModulo public GrupoModuloMap() { Schema(Const.SCHEMA); Table(Const.TB_EMAIL_GRUPO_MODULO); CompositeId() .KeyReference(x => x.Grupo, Const.ID_GRUPO) .KeyReference(x => x.Modulo, Const.ID_MODULO); Map(x => x.GrupoId).Column(Const.ID_GRUPO).ReadOnly(); Map(x => x.ModuloId).Column(Const.ID_MODULO)

Oracle Delete Statement: how many rows have been deleted by cascade delete

跟風遠走 提交于 2019-12-06 11:55:37
I'm executing a statement like DELETE FROM USER WHERE USER_ID=1; In SQLDeveloper. As the user is referenced in many tables (for example the user has an order, settings, ...) we activated ON DELETE CASCADE so that we do not have to delete each and every row manually. However while developing we are interested to know how many rows and and in which tables are "automatically" deleted by cascade delete. Is there any way to find this out. Either by SQL-Statement, directly in sqldeveloper from a logfile or any other idea? whilst this is not possible with sql%rowcount, it is possible if you write

Entity Framework cascading delete problems - Foreign key set to null

冷暖自知 提交于 2019-12-06 09:24:21
I have the following Model which I mapped with the Entity Framework: Mitglied -> Auftrag -> Teilprojekt I have set up everything in the database with foreign keys and "on delete cascade". If I perform some tests on the database everything works fine. The problem arises as soon as I use the Entity Framework to add and especially delete objects. Consider the following code: Mitglieder m1 = new Mitglieder(); m1.Name = "erstes"; Auftraege a1 = new Auftraege(); a1.Name = "a1"; m1.Auftraege.Add(a1); Teilprojekte t1 = new Teilprojekte(); t1.Name = "t1"; a1.Teilprojekte.Add(t1); context

[MySQL]: DELETE rows from two dependent tables

无人久伴 提交于 2019-12-06 03:06:57
问题 I am attempting to delete all rows in two dependent tables based on a third tables ID. Table structure: Transaction -Transaction_ID (primary) -Timestamp Purchase -Item_ID -Transaction_ID -Purchase_ID (primary) Item -Item_ID (primary) -Client_ID I would like to delete all rows from transaction/purchase that match the Client_ID in item. Sounds simple enough... even I can wrap my novice mind around that... DELETE dbName.t FROM dbName.Transaction t JOIN dbName.Purchase p ON p.Transaction_ID = t

Grails belongsTo cascade on delete when belongsTo specifies multiple classes?

旧巷老猫 提交于 2019-12-06 02:04:12
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? I have tested it, it follows the cascade rule: if you delete Owner, Dog will be deleted by cascade, but Sitter will remain. And it's reasonable: Sitter is independent with Owner.

tsql script to add delete cascade to existing tables

此生再无相见时 提交于 2019-12-05 16:32:55
问题 is there a script that can be used to enable cascaded deletion for existing tables. Thanks. 回答1: 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