title: JPA - @PreRemove method behaviour
body: <p>I have 2 entities with many-to-many relationship. The Movie Entity is the owner of this relation, so when I want to delete an Actor Entity I use a method annotated @PreRemove to delete any occurrences of Actor ID in Movie cast to avoid "Foreign key violation exception".</p>
  
  <p><strong>Movie class</strong></p>
  
  <pre><code>@Entity
  public class Movie extends AbstractBusinessObject{
  
      @ManyToMany
      private Map&lt;String, Actor&gt; cast;
  
      // setters and getters
  
      public void removeCastMember(Actor actor){
  
          for (Entry&lt;String, Actor&gt; e : cast.entrySet()) {
              if(e.getValue().id.equals(actor.id)){
                  cast.remove(e.getKey());
              }
          }
  
      } // removeCastMember()
  
  }
  </code></pre>
  
  <p><strong>Actor class</strong></p>
  
  <pre><code>@Entity
  public class Actor extends AbstractBusinessObject{
  
      @ManyToMany(mappedBy = "cast")
      private Set&lt;Movie&gt; movies;
  
      // setters and getters
  
      @PreRemove
      private void removeActorFromMovies() {
          for (Movie m : movies) {
              m.removeCastMember(this);
          }
      }
  
  }
  </code></pre>
  
  <p>To be clear, from my testing, <strong>it works - movie objects are correctly updated</strong> in the database. However, I cannot understand how is it possible when there are no calls to saveOrUpdate() or persist/merge those objects.</p>