title: Hibernate-Bidirectional mapping and ORM mapping
body: <p>In that example <a href="https://dzone.com/articles/synchronization-methods-for-many-to-many-associati" rel="nofollow noreferrer">https://dzone.com/articles/synchronization-methods-for-many-to-many-associati</a></p>
  <p>it is said</p>
  <blockquote>
  <p>One more thing that we need to remember is that we need to keep the
  bidirectional association synchronized. E.g., when we add a Tag
  instance to a tags set in a PostWe should not forget to add this Post
  to the corresponding posts set in the Tag entity. The same logic
  applies to the Tag removal process. To implement this approach, we add
  synchronization methods to both entities. For the sake of simplicity,
  only methods for the Post entity are provided; for the TagThey will be
  pretty the same.</p>
  </blockquote>
  <pre><code>public void addTag(Tag tag) {
      tags.add(tag);
      tag.getPosts().add(this);
  }
  
  public void removeTag(Tag tag) {
      tags.remove(tag);
      tag.getPosts().remove(this);
  }
  </code></pre>
  <p>The question I have is , does</p>
  <pre><code>tag.getPosts().add(this)
  </code></pre>
  <p>mean &quot;fetch ALL the tags that the Post has and then add the new Tag at then end of them?&quot;
  So does tag.getPosts() fire a select query to fetch ALL the tags of the post first and then do an insert ? If that is so,isn't that hugely inefficient?</p>