I'm using Hibernate to store information about article citations. And I annotated my class in this way in order to express a relationship between two articles.
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "CITATIONS")
private Set<Article> citingArticles = new HashSet<Article>();
Unfortunately this is translated with a UNIQUE constraint on the citingArticle, which means that I can only have an article to cite a single other article.
Of course this is not what I'd like to have, how can I remove the UNIQUE constraint?
If you have a many-to-many relationship, you need to model it with @ManyToMany
:
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "CITATIONS")
private Set<Article> citingArticles = new HashSet<Article>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With