Hibernate @OneToMany and UNIQUE constraint

I use Hibernate to store article link information. And I annotated my class in such a way as to express the relationship between the two articles.

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "CITATIONS") private Set<Article> citingArticles = new HashSet<Article>(); 

Unfortunately, this translates with a UNIQUE restriction on the article being cited, which means that I only have an article in which one other article can be cited.

Of course, this is not what I would like to have, how can I remove the UNIQUE constraint?

+7
source share
1 answer

If you have a many-to-many relationship, you need to model it using @ManyToMany :

 @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "CITATIONS") private Set<Article> citingArticles = new HashSet<Article>(); 
+7
source

All Articles