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