-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-Many orphan deletion leads to unexpected behaviour
PostPosted: Fri Jun 18, 2010 6:06 am 
Newbie

Joined: Fri Jun 18, 2010 5:36 am
Posts: 1
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;
    ...
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.