I currently have a Many to Many relationship between Events and Users. The auto generated table in my DB called event_registrations keeps track of the relationship and which user goes to which event based on their ids.
What I want to do is have a controller method that takes in an Event id together with a list of user IDs so that the given users get removed from the given event.
Here are my model classes:
What I've tried so far in the EventController:
This runs without problems but the the entries still exist in the join table afterwards. When debugging this, the users do get deleted from the Event object but the changes don't get persisted to the database.
Depending on the JPA implementation, you may have to remove from the owning side. I've had problems after migrating from WebLogic + TopLink to Spring Boot + Hibernate where many-to-many links weren't updated correctly if I updated the non-owning side.
In your case, you have two sides: User is the owning side, and Event is the non-owning side (you can see this from the "mappedBy" on Event). That means that you should remove from User.eventRegistrations, not from Event.userList.
A quick attempt without any additional helper methods: