In my appliction I have a many-to-many association between groups and articles.
I have an unexpected behaviour when I remove an article from a group while my article still belongs to other groups.
The removed article and the association between the other group get deleted in the DB. As the article is not an orphan
I wouldn't expect it to be deleted.
Code:
class Group {
...
@ManyToMany( targetEntity = Article.class, fetch = FetchType.LAZY )
@Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
@Fetch( FetchMode.SELECT )
...
private List<Article> articles;
...
}
class Article {
...
@ManyToMany( targetEntity = Group.class, fetch = FetchType.LAZY, mappedBy = "articles" )
@Fetch( FetchMode.SELECT )
private List<Group> groups;
...
}