[英]Spring JPA and remove entries from @ManyToMany
As touched on in the following: 如下所述:
when removing entries from @ManyToMany
mappings, there is an element of manual tweaking involved to remove the foreign keys. 从
@ManyToMany
映射中删除条目时,有一个手动调整元素来删除外键。
I have been using my own JPA CRUD for years and have a nice solution for this: CrudDao eg NoteDao . 我多年来一直在使用自己的JPA CRUD,并为此提供了一个很好的解决方案: CrudDao,例如NoteDao 。
But I've been recently very impressed by Spring JPA and the ability to autogenerate Cruds by declaring an interface and then creating similarly named namedQuery
s on the @Entity
. 但是最近我对Spring JPA以及通过声明一个接口然后在
@Entity
上创建类似命名的namedQuery
来自动生成Cruds的能力印象深刻。
But how do I fix the @ManyToMany
remove problem? 但是如何修复
@ManyToMany
删除问题呢? I'll essentially have remove
methods on my Crud that expose this "feature" of JPA. 我基本上已经
remove
了我的Crud上的方法,揭示了JPA的这个“特性”。
I appear to have solved this using @PreRemove
, as noted in https://stackoverflow.com/a/14911910/1041691 我似乎已经使用
@PreRemove
解决了这个@PreRemove
,如https://stackoverflow.com/a/14911910/1041691中所述
eg https://github.com/fommil/zibaldone/blob/master/src/main/java/com/github/fommil/zibaldone/Note.java#L74 例如https://github.com/fommil/zibaldone/blob/master/src/main/java/com/github/fommil/zibaldone/Note.java#L74
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.