У меня есть три таблицы
article(id, title, content)
article_tag(article_id, tag_id)
tag(id, name) // name(unique=true)
Article.java
@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<Tag> tags = new HashSet<>();
private Timestamp createdAt;
private Timestamp updatedAt;
}
Tag.java
@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<Article> articles = new HashSet<>();
}
Я знаю, как вставить статьи, но как можноЯ вставляю дубликаты тегов?
Тег таблицы уже есть ("a", "b", "c")
![enter image description here](https://i.stack.imgur.com/1LhBQ.png)
Я хочу вставить статью стег "а", как это сделать?