6

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.

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 namedQuerys on the @Entity.

But how do I fix the @ManyToMany remove problem? I'll essentially have remove methods on my Crud that expose this "feature" of JPA.

Community
  • 1
  • 1
fommil
  • 5,757
  • 8
  • 41
  • 81

1 Answers1

4

I appear to have solved this using @PreRemove, as noted in https://stackoverflow.com/a/14911910/1041691

e.g. https://github.com/fommil/zibaldone/blob/master/src/main/java/com/github/fommil/zibaldone/Note.java#L74

Community
  • 1
  • 1
fommil
  • 5,757
  • 8
  • 41
  • 81