hibernate-cascade

Hibernate OnDelete Cascade not working for MySql but Works on postgres and Ms-Sql

自作多情 提交于 2019-12-20 10:54:27
问题 I'm having 2 Entities. Thread entity and Post entity using OnetoOne mapping from Post->Thread. A Thread entity contains Numerous Posts . I know i should have used OnetoMany instead of OnetoOne, but for avoiding all the Collections problems i'm using OnetoOne Now the problem is, when i delete a Thread , all the post associated with it must also be removed. I'm successful in doing it by using @OnDelete(action = OnDeleteAction.CASCADE) But it works only on Postgres and Ms-SQl but not on MySql

can't get cascade save nor delete on embedded class ref to work

痴心易碎 提交于 2019-12-12 02:18:47
问题 i've created two simple grails V3 domain classes where location is embedded attribute type in parent Venue like this import java.time.LocalDate class Venue { String name LocalDate dateCreated LocalDate lastVisited LocalDate lastUpdated GeoAddress location static hasOne = [location:GeoAddress] static embedded =['location'] static constraints = { lastVisited nullable:true location nullable:true } static mapping = { location cascade: "all-delete-orphan", lazy:false //eager fetch strategy } }

Hibernate cascade many to many creates duplicates in child reference

ぃ、小莉子 提交于 2019-12-11 09:46:52
问题 Ok so I'm new to hibernate. The question is about cascade many-to-many, avoiding to add duplicate values. So I follow this example. tutorialspoint hibernate many to many mapping The problem is this, that if I run program twice it adds duplicate values to certificate table. After I insert values to employee table. It cascades and inserts values to certificate table: id certificate_name 1 PMP 2 MBA 3 MCA After I run this example second time it does the same actions. id certificate_name 1 PMP 2

Grails many-to-many associations and preventing cascade

六月ゝ 毕业季﹏ 提交于 2019-12-07 14:51:46
问题 So, we have a many-to-many relationship between Customer and Role, set up as: Customer { static hasMany = [roles: Role] } Role { static hasMany = [customer: Customer] static belongsTo = Customer } The Role object has only a name and a set of permissions. We don't want to cascade saves from Customer -> Role, as Role should only get modified directly. I added: static mapping = { roles cascade: 'none' } but, whenever, I create a customer, the role table gets updated as well. Nothing changes,

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"

Can Hibernate delete orphaned collections when updating a detached object?

半城伤御伤魂 提交于 2019-12-03 12:21:25
问题 I know that deleting orphaned child objects is a common question on SO and a common problem for people new to Hibernate, and that the fairly standard answer is to ensure that you have some variation of cascade=all,delete-orphan or cascade=all-delete-orphan on the child collection. I'd like to be able to have Hibernate detect that child collection has been emptied/removed from the parent object, and have the rows in the child table deleted from the database when the parent object is updated.

Can Hibernate delete orphaned collections when updating a detached object?

三世轮回 提交于 2019-12-03 01:52:59
I know that deleting orphaned child objects is a common question on SO and a common problem for people new to Hibernate, and that the fairly standard answer is to ensure that you have some variation of cascade=all,delete-orphan or cascade=all-delete-orphan on the child collection. I'd like to be able to have Hibernate detect that child collection has been emptied/removed from the parent object, and have the rows in the child table deleted from the database when the parent object is updated. For example: Parent parent = session.get(...); parent.getChildren().clear(); session.update(parent); My

Hibernate OnDelete Cascade not working for MySql but Works on postgres and Ms-Sql

[亡魂溺海] 提交于 2019-12-03 00:40:55
I'm having 2 Entities. Thread entity and Post entity using OnetoOne mapping from Post->Thread. A Thread entity contains Numerous Posts . I know i should have used OnetoMany instead of OnetoOne, but for avoiding all the Collections problems i'm using OnetoOne Now the problem is, when i delete a Thread , all the post associated with it must also be removed. I'm successful in doing it by using @OnDelete(action = OnDeleteAction.CASCADE) But it works only on Postgres and Ms-SQl but not on MySql(Tried InnoDb as well). The on delete cascade is not generated in the schema generation query. Following

IllegalStateException with Hibernate 4 and ManyToOne cascading

核能气质少年 提交于 2019-11-27 08:51:18
I've got those two classes MyItem Object: @Entity public class MyItem implements Serializable { @Id private Integer id; @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) private Component defaultComponent; @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) private Component masterComponent; //default constructor, getter, setter, equals and hashCode } Component Object: @Entity public class Component implements Serializable { @Id private String name; //again, default constructor, getter, setter, equals and hashCode } And I'm tring to persist those with the following code

IllegalStateException with Hibernate 4 and ManyToOne cascading

孤者浪人 提交于 2019-11-26 14:19:55
问题 I've got those two classes MyItem Object: @Entity public class MyItem implements Serializable { @Id private Integer id; @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) private Component defaultComponent; @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) private Component masterComponent; //default constructor, getter, setter, equals and hashCode } Component Object: @Entity public class Component implements Serializable { @Id private String name; //again, default