title: jpa many to many unique=true, how to save
body: <p>I have three table</p>
  
  <pre><code>article(id, title, content)
  article_tag(article_id, tag_id)
  tag(id, name) // name(unique=true)
  </code></pre>
  
  <p>Article.java</p>
  
  <pre><code>@Data
  @Entity
  public class Article {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @Column(nullable = false)
      private String title;
  
      @Column(nullable = false, unique = true, columnDefinition = "text")
      private String content;
  
      @JsonIgnore
      @ManyToMany(cascade = CascadeType.PERSIST)
      @JoinTable(name = "article_tag",
              joinColumns = @JoinColumn(name= "article_id"),
              inverseJoinColumns = @JoinColumn(name = "tag_id"))
      private Set&lt;Tag&gt; tags = new HashSet&lt;&gt;();
  
      private Timestamp createdAt;
  
      private Timestamp updatedAt;
  }
  </code></pre>
  
  <p>Tag.java</p>
  
  <pre><code>@Data
  @Entity
  public class Tag {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @Column(nullable = false, unique = true)
      private String name;
  
      @JsonIgnore
      @ManyToMany(cascade = CascadeType.PERSIST, mappedBy = "tags")
      private Set&lt;Article&gt; articles = new HashSet&lt;&gt;();
  }
  </code></pre>
  
  <p>I know how to insert articles, but how can I insert duplicate tags?</p>
  
  <p>Table tag already have ("a", "b", "c")</p>
  
  <p><img src="https://i.stack.imgur.com/1LhBQ.png" alt="enter image description here"></p>
  
  <p>I want to insert a article with tag "a", how to do?</p>