Cascade

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

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

Entity Framework Code first - FOREIGN KEY constraint problem

孤人 提交于 2019-12-04 19:58:39
问题 I'm new to EF code first principal and currently with no clue what to do.. I have 2 POCO classes.. public class Problem { public int ProblemID { get; set; } public int UserID { get; set; } public int CategoryID { get; set; } public int RatingID { get; set; } public string Title { get; set; } public string Description { get; set; } public double Latitude { get; set; } public double Longitude { get; set; } public int State { get; set; } public DateTime CreatedOn { get; set; } public virtual

MySql on delete cascade concept?

…衆ロ難τιáo~ 提交于 2019-12-04 19:51:41
I am trying to figure out how cascade delete works. I know the general concept but not the specifics of it. I have 3 tables (a)||---|<(B)>o---||(C) Table A: Aid Tag Table B: Aid (f) Cid (F) Table C: Cid Other A row in table A must have at least one reference to table c or else it should be deleted. A row in table A is made only when Table C tries creating a tag that does not exist. If table C removes that tag and no other rows from table C reference that tag then the tag should be removed. If another row from table C references that tag then the tag should not be deleted. If I set Table B [Aid

Many to Many: Delete one side, the relationship entry BUT don't delete the other side

╄→гoц情女王★ 提交于 2019-12-04 17:10:21
问题 I want to delete an user which has many usergroups but those usergroups don't belong exclusivly to this user: other users can also be using this usergroups. And usergroups can exist even if no user references them. I want to map the many-to-many relationship so that if a user is deleted , the relationship is automatically deleted but NOT the usergroup ? I tried Cascade.All as I thought cascades on many-to-many affect the relationship but not the other side. I thought that only Cascade

How to persist a new entity containing multiple identical instances of another unpersisted entity with spring-boot and JPA?

£可爱£侵袭症+ 提交于 2019-12-04 17:06:26
Overview: I'm building a spring-boot application which, in part, retrieves some entities from an external REST service and compares it to previous versions of the entity held locally in a database. I'm injecting EntityManager with @PersistenceContext , and using that to work with the database, as there are many entity types, and the type is initially unknown to the module. I could get a JpaRepository from a factory, but the number of different entity types is liable to grow, and I'd rather not rely on that if at all possible. Problem: When the module retrieves an entity which it doesn't hold

JPA Entity relationship: Cascade on delete

╄→гoц情女王★ 提交于 2019-12-04 14:26:53
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 when I delete a row from child ( ie. Product), will the Supplier will also get deleted? Or, it is only

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

SQL Server - Cascading DELETE with Recursive Foreign Keys

旧街凉风 提交于 2019-12-04 07:11:04
I've spent a good amount of time trying to figure out how to implement a CASCADE ON DELETE for recursive primary keys on SQL Server for some time now. I've read about triggers, creating temporary tables, etc but have yet to find an answer that will work with my database design. Here is a Boss/Employee database example that will work for demonstration purposes: TABLE employee id|name |boss_id --|---------|------- 1 |John |1 2 |Hillary |1 3 |Hamilton |1 4 |Scott |2 5 |Susan |2 6 |Seth |2 7 |Rick |5 8 |Rachael |5 As you can see, each employee has a boss that is also an employee. So, there is a PK

JPA CascadeType.All doesn't delete parent and child rows

烈酒焚心 提交于 2019-12-04 05:45:30
问题 It's always been trouble handling cascades in JPA or Hibernate but i really didn't get it now. I want to delete a parent row brand and childs that are referencing to it. I used CascadeType.ALL but no luck. Here are my models (Transact <- TransactProduct -> Product -> Brand -> Customer), I'm showing only relations for clarity: @Entity @Table(name = "customer") public class Customer { @OneToMany(fetch = FetchType.EAGER, mappedBy = "customer", cascade = CascadeType.ALL) private Collection<Brand>