Hi
I am a newbie to hibernate and I'm using hibernate annotations for my project. The entity classes are as follows
Code:
@Entity
public class Artist
{
Integer artistId;
String artistName;
............
List<Album> albumList;
@OneToMany(mappedBy = "artist", cascade = CascadeType.ALL)
public List<Album> getAlbumList() {
return albumList;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getArtistId() {
return artistId;
}
..........................
}
@Entity
public class Album
{
Integer id;
Artist artist;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getId() {
return id;
}
@ManyToOne
@JoinColumn(name = "artistId")
public Artist getArtist() {
return artist;
}
.....................
}
..........................
hibernateSession.update(artist);
..........................
I have a problem when updating an 'artist' object. The mapped 'album' objects also gets updated but they do not get deleted according to the number of objects in the 'albumList'
eg: if 3 albums were added to an artist and later on if one album is removed it is not reflected in the db when updating an 'artist' object. but if an album name is changed or a new album is added, that change is reflected in the db when update(artist) is called.
what should be done to remove records when updating an object in this scenario
Thanks