-->
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: CascadeType.ALL saving top entity saves linked entity
PostPosted: Tue Feb 28, 2012 6:45 pm 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
Have an entity class (Song) with a @OneToMany mapping to another entity (CoverArt), and cascade set to ALL because it seemed easier to just have to save the main entity and let it take care of persisting the cover art

@Audited
@Entity
public class Song
{
@Id
@GeneratedValue
private Integer recNo;

@Version
private int version;

@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
private List<CoverArt> coverArts;

....

}

But I found at a later point in the code if I just retrieved and instance of the class from the database and then within session modified just one field in the Song entity that would cause it to update all the cover art entities linked to that song even though nothing had changed for the cover art, why is it doing this ?

Also, I don't think it causes the problem but I am using Envers and the (seemingly) needless extra updates to the CoverArt table have the knock effect of causing Envers to create unneccessary Audit Tables as well.

If I remove the CascadeType annotation modifying the one field does not cause the cover art entities to be updated and everything works okay as long as I add the extra logic for when I do add cover art but I was hoping I didn't need to do this.

http://stackoverflow.com/questions/9490 ... ssary-upda


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.