Spring JPA and remove entries from @ManyToMany
I appear to have solved this using @PreRemove
, as noted in https://stackoverflow.com/a/14911910/1041691
fommil
Co-founder of the Free High School Science Textbooks: now being taken forwards by Siyavula.com. As of May 2012, the South African government has printed and distributed 4,424,500 of our books to every registered learner in the country between the ages of 13 and 16. I am also co-founder of ThinkTank Maths Limited: a mathematics research organisation which provides innovative solutions to blue chips. I have a Ph.D. in mathematical physics, an M.Sc. in theoretical physics and a B.Sc. (with Honours) in Physics with Astrophysics. I am the author of several open source projects, including: netlib-java and matrix-toolkits-java. My preferred programming languages are Scala, Java and R and many people comment on the fact that I touch type on a DVORAK keyboard.
Updated on June 05, 2022Comments
-
fommil almost 2 years
As touched on in the following:
- Cascade on delete using unidirectional Many-To-Many mapping
- How to remove entity with ManyToMany relationship in JPA (and corresponding join table rows)?
- JPA JPQL: select items when attribute of item (list/set) contains another item
when removing entries from
@ManyToMany
mappings, there is an element of manual tweaking involved to remove the foreign keys.I have been using my own JPA CRUD for years and have a nice solution for this: CrudDao e.g. 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
.But how do I fix the
@ManyToMany
remove problem? I'll essentially haveremove
methods on my Crud that expose this "feature" of JPA.