Let's say there are two simple entities:
@Entity
public class Author {
private String name;
@ManyToMany
private List<Book> books;
@Entity
public class Book {
private String title;
@ManyToMany
private List<Author> authors;
Next I am sending a PATCH
request to update the Author:
http://localhost:8080/authors/1
body:
{
"books": [
"http://localhost:8080/books/2",
"http://localhost:8080/books/3"
]
}
There is a handler:
@RepositoryEventHandler
public class AuthorEventHandler {
@HandleBeforeSave
public void handleBeforeAuthorSave(Author author) {
System.out.println("handleBeforeSave Author: " + author);
}
@HandleAfterSave
public void handleAfterAuthorSave(Author author) {
System.out.println("HandleAfterSave Author: " + author);
}
@HandleBeforeLinkSave
public void handleBeforeLinks(Author author, List<Book> books) {
System.out.println("handleBeforeLinks Author: " + author);
}
@HandleAfterLinkSave
public void handleAfterLinks(Author author, List<Book> books) {
System.out.println("handleAfterLinks Author: " + author);
}
}
The handler catches only the AfterSaveEvent
and BeforeSaveEvent
.
Spring does not produce Before-AfterLinkSave
events.
EDIT:
I've noticed the method:
@RequestMapping(value = BASE_MAPPING, method = { PATCH, PUT, POST }
createPropertyReference()
With the BASE_MAPPING = "/{repository}/{id}/{property}";
So the PATCH request on the http://localhost:8080/authors/1/books
triggers it. It's not the way I thought about from the start.