Cascade

Implementing Cascade Delete in a self referencing table in EF Core 2

柔情痞子 提交于 2019-12-08 05:39:45
问题 How can I implement Cascade Delete in a self referencing table in EF Core 2 (code first)? (For example there is a Comment Table and man can reply to a comment and this reply can reply by another.) public class Comment { public virtual int Id { get; set; } public virtual int? ParentId { get; set; } public Comment Parent { get; set; } public virtual IList<Comment> Replies { get; set; } public virtual string Description { get; set; } public virtual Article Article { get; set; } } 回答1: The

Hibernate cascading

余生颓废 提交于 2019-12-08 02:13:51
问题 All what Hibernate reverse engineering generates is something like this @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "column_id") public Itinerary getColumnId() { return this.columnId; } I want this scenario: when session flushes, first all constructed childs were saved, then the parent object, according to FK constraints. Of course, children need to be saved first (automatically!), 'cause there are FK constraints. You'd tell me: there's a CASCADE option, but how to use it with JPA?

Cascade deleting from join table with @ManyToMany annotation

筅森魡賤 提交于 2019-12-07 12:14:53
问题 Hi I got a problem with mapping my entities. I'm using JPA2 and Hibernate implementation. I got tables with @ManyToMany annotation http://img204.imageshack.us/img204/7558/przykladd.png I mapped it with : @Entity @Table("employee") class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; @Column private String name; @ManyToMany @JoinTable(name = "proj_emp", joinColumns = @JoinColumn(name = "employee_id", referencedColumnName = "id"), inverseJoinColumns =

Merge Primary Keys - Cascade Update

旧城冷巷雨未停 提交于 2019-12-07 05:20:58
问题 Is there a way to merge two primary keys into one and then cascade update all affected relationships? Here's the scenario: Customers (idCustomer int PK, Company varchar(50), etc) CustomerContacts (idCustomerContact int PK, idCustomer int FK, Name varchar(50), etc) CustomerNotes (idCustomerNote int PK, idCustomer int FK, Note Text, etc) Sometimes customers need to be merged into one. For example, you have a customer with the id of 1 and another with the id of 2. You want to merge both, so that

Hibernate Cascade PERSIST

北城余情 提交于 2019-12-07 01:07:36
问题 I have a general question about Hibernate that I'm batteling with. I have class A and class B, where B is dependent on A In my code when I call em.persist(objOfTypeA) I would expect the insert to go and insert into both tables AAA and BBB. If I manually presist A get A's ID and fill it in the list for each object and then persist that list, things are working. But I would expect this to happen magically by Hibernate. Am I doing something wrong? Or am I just expecting too much of Hibernate?

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"

Oracle经典建表语句【scott建表】

痴心易碎 提交于 2019-12-06 12:01:36
Oracle经典建表语句【scott建表】 ========================================== create table EMP ( EMPNO NUMBER(4) PRIMARY KEY, ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7,2), COMM NUMBER(7,2), DEPNO NUMBER(4) ); CREATE TABLE Dept( DEPTNO NUMBER(4), DNAME VARCHAR2(14), LOC VARCHAR2(13) ); CREATE TABLE Salgrade ( GRADE NUMBER, LOSAL NUMBER, HISAL NUMBER ); CREATE TABLE Bonus ( ENAME VARCHAR(10), JOB VARCHAR2(9), SAL NUMBER, COMM NUMBER ); INSERT INTO Dept VALUES (10,'财务处','纽约'); INSERT INTO Dept VALUES (20,'发展部','达拉斯'); INSERT INTO Dept VALUES (30,'销售部','芝加哥'); INSERT INTO

Hibernate cascading

血红的双手。 提交于 2019-12-06 11:31:11
All what Hibernate reverse engineering generates is something like this @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "column_id") public Itinerary getColumnId() { return this.columnId; } I want this scenario: when session flushes, first all constructed childs were saved, then the parent object, according to FK constraints. Of course, children need to be saved first (automatically!), 'cause there are FK constraints. You'd tell me: there's a CASCADE option, but how to use it with JPA? I tried adding cascade like this: @ManyToOne(fetch = FetchType.LAZY, cascade=CascadeType.PERSIST)

JPA Entity relationship: Cascade on delete

假装没事ソ 提交于 2019-12-06 06:37:03
问题 I am using spring, JPA with Hibernate. I got the following entities: @Entity @Table(name = "Supplier") public class Supplier { @Id @Column(name = "Supplier_ID", nullable = false) private Integer supplierId; ... } and, @Entity @Table(name = "Product") public class Product { @Id private Integer productId; @ManyToOne(cascade = CascadeType.ALL) @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name = "Supplier_ID") private Supplier supplier; ... } Now, my question is, with the given schema