0

When I delete a record from table r, it in turn deletes a record from a linking table b because r has a Many-To-Many relationship with b and I am using Hibernate Join Table to associate them. Here is where my problem comes: I have a view that relies on that linking table, b, and the result of deleting r causes a delete from the view but now that view record is no longer there. I get a Stale State exception because of this.

Can I ask Hibernate to ignore cascade deletes? I have tried evicting the b table records before trying to delete, but that doesn't appear to work.

4

1 回答 1

0

对此有点生疏,但我相信您可以在联接声明注释中控制级联行为,如下所示:

@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<OtherData> dontDeleteMe;

这将级联持久化和合并操作,但不会级联更新或删除。

查看此页面以获取更多详细信息:

http://vladmihalcea.com/a-beginners-guide-to-jpa-and-hibernate-cascade-types/

于 2015-11-11T18:15:34.097 回答