cascading-deletes

Entity Framework Cascade Delete For Inherited class

丶灬走出姿态 提交于 2019-12-05 13:42:01
Apparently Cascade Deleting with Entity Framework is very confusing. I found lot's of questions but I have not found a solution for my problem. If I manually set the "Delete Rule" to cascade it all works. But via Fluent API I haven't found a way to set this property in the database. In my case I have a base class (with it's own table in the database) public abstract class PropertyBase { public int PropertyID { get; set; } public string Name { get; set; } public virtual AspectBase AspectBase { get; set; } } And I have derived classes which are stored Table Per Type. public class TextProperty :

Hibernate Cascading Delete Not working as expected

江枫思渺然 提交于 2019-12-05 08:59:54
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, employee_id number(12) foreign key references employee.employee_id not null, role varchar2(50) ); My

Grails - multiple belongsTo of same class with cascading deletion

别说谁变了你拦得住时间么 提交于 2019-12-05 05:22:21
This one is for the Grails users here. I asked it on the grails - user mailing list, but I figured since I've been fighting this for a couple of days I should cast as wide a net as possible. I'm having some difficulty with trying to model relationships between two objects of the same type in another object (different type) referencing the two objects. As an example of what I'm trying to do, suppose you're modeling relationships among family members. Any given relationship "belongsTo" two different family members. So: class Person { hasMany[relationships: Relationship] static mappedBy =

How to find if a referenced object can be deleted?

时间秒杀一切 提交于 2019-12-05 01:48:42
I have an object called "Customer" which will be used in the other tables as foreign keys. The problem is that I want to know if a "Customer" can be deleted (ie, it is not being referenced in any other tables). Is this possible with Nhibernate? Jaguar What you are asking is to find the existence of the Customer PK value in the referenced tables FK column. There are many ways you can go about this: as kgiannakakis noted, try to do the delete and if an exception is thrown rollback. Effective but ugly and not useful. This also requires that you have set a CASCADE="RESTRICT" in your database. This

How to enforce referential integrity on Single Table Inheritance?

一笑奈何 提交于 2019-12-04 23:57:05
I've read some of Bill Karwin's answers about single table inheritance and think this approach would be good for the setup I am considering: Playlist -------- id AUTO_INCREMENT title TeamPlaylist ------------ id REFERENCES Playlist.id teamId REFERENCES Team.id UserPlaylist ------------ id REFERENCES Playlist.id userId REFERENCES User.id PlaylistVideo ------------- id playlistId REFERENCES Playlist.id videoId REFERENCES Video.id All the CASCADE options are set to DELETE which will work correctly for when a Playlist is deleted, however, what happens if a User or Team is deleted? ie. If a User is

Figure out if a table has a DELETE on CASCADE

主宰稳场 提交于 2019-12-04 22:49:53
Can I know if a database have DELETE ON CASCADE with a query? 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_CONSTRAINTS r JOIN information_schema.KEY_COLUMN_USAGE k USING (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT

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

对着背影说爱祢 提交于 2019-12-04 20:09:23
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 deleteByListkeyId(@Param("listkeyId") Integer listkeyId); it says: com.mysql.jdbc.exceptions.jdbc4

JPA relationship not getting updated when children are removed

扶醉桌前 提交于 2019-12-04 13:04:08
问题 Given the following scenario: @Entity public class A { @OneToMany(mappedBy = "a", cascade = CascadeType.ALL) private List<B> bList; } @Entity public class B { @ManyToOne() @JoinColumn(name = "a_id", referencedColumnName = "id") private A a; @ManyToOne() @JoinColumn(name = "c_id", referencedColumnName = "id") private C c; } @Entity public class C { @OneToMany(mappedBy="c", cascade=CascadeType.ALL, orphanRemoval=true) @CascadeOnDelete // eclipselink specific optimization annotation private List

ON DELETE CASCADE option not in generated when using ddl schema generation on Mysql

不羁岁月 提交于 2019-12-04 12:19:07
问题 In a Maven-Spring-Hibernate-MySql running on Tomcat web app I'm using hibernate ddl to generate my DB schema with MySQL5InnoDBDialect. The schema is generated just fine except the cascade option for foreign-keys. For example I have this structure: A user object that holds user-details object, both sharing the same key: @Entity @Table(name = "Users") public class User implements Serializable { private static final long serialVersionUID = -359364426541408141L; /*--- Members ---*/ /** * The

How do I delete a child entity from a parent collection with Entity Framework 4?

佐手、 提交于 2019-12-04 10:51:08
问题 I'm using Entity Framework 4 and have a one-to-many relationship between a parent and child entity. I'm trying to delete a child using the parent repository by removing it from the parent's children collection: public virtual void RemoveChild(Child child) { children.Remove(child); } When I try to save the changes I get the following error: A relationship from the 'ParentChild' AssociationSet is in the 'Deleted' state. Given multiplicity constraints, a corresponding 'Child' must also in the