title: Is it possible to implement (0..n) many to many (using @ManyToMany annotation) relation in JPA?
body: <p>I'm looking for a way to implement (0..n) many to many relation in JPA, much possibly using @ManyToMany annotation. All examples that I found were about (1..n) relations. What I need to accomplish:
  - I've got two entities: Contact and Tag. Each Contact can have 0..n Tags. Each Tag can have 0..n Contacts. From SQL point of view it would look like 
  this: Contact (0..n) --- (1) Contact_has_Tag (1) --- (0..n) Tag.</p>
  
  <p>Code below is not working for me because JPA is linking columns with INNER JOIN. </p>
  
  <p>OFC I could do this using intermediate entity and @OneToMany and @ManyToOne annotations, but I want a simpler sollution.</p>
  
  <pre><code>@Data
  @Entity
  public class Contact {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @JsonIgnore
      private long id;
  
      @Column(unique = true)
      private String email;
  
      // ...
  
      @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      @JsonIgnore
      @JoinTable(
      name = "contact_has_tag",
      joinColumns = @JoinColumn(name = "contact_id", referencedColumnName = "id", updatable = false, nullable = true),
      inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id", updatable = false, nullable = true))
      private List&lt;ContactTag&gt; contactTags = new ArrayList&lt;ContactTag&gt;();
  
  }
  
  @Entity
  @Data
  public class ContactTag {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;
  
      @Column
      private String name;
  
      @ManyToMany(mappedBy="contactTags", fetch = FetchType.LAZY)
      @JsonIgnore
      private List&lt;Contact&gt; contacts = new ArrayList&lt;Contact&gt;();
  
  
  }
  </code></pre>
  
  <p>Any ideas how it should be done?</p>