Hi
I have 2 classes PlayLog and PlayLogImage
and i have @ManyToMany association between them
In general , a PlayLog can have multiple PlayLogImage's
and the same PlayLogImage can be related to multiple PlayLogs
The functionality that i want to achieve is that the
PlayLogImage will be deleted when no Play Log is using it
I was thinking that "DELETE_ORPHAN" will do it
But i get this exception
Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (RAMP25.FK_IMAGE_PLAY_LOG) violated - child record found
These are the classes (notice it is not bi-directional)
Code:
@Entity
@Table(name = "PLAY_LOG")
public class PlayLog {
private List<PlayLogImage> images;
@ManyToMany(cascade={})
@Cascade(value={org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
@JoinTable(name="PLAY_LOG_IMAGES_IMAGES")
@IndexColumn(name = "img_order", base=1)
@ForeignKey(name="FK_PLAY_LOG_IMAGE", inverseName = "FK_IMAGE_PLAY_LOG")
public List<PlayLogImage> getImages() {
return images;
}
public void setImages(List<PlayLogImage> images) {
this.images = images;
}
}
Code:
@Table(name = "PLAY_LOG_IMAGES")
public class PlayLogImage extends BaseImage {
...
}
In order to delete the Play Logs i use this code ( get the list of Play logs that i want to delete , and delete them in a loop)
Code:
List<PlayLog> playLogs = playLogsDAO.getPlayLogs(detachedCriteria);
for (PlayLog playLog : playLogs){
playLogsDAO.remove(playLog);
}
i noticed that when i remove the cascade then the deletion of the PlayLogs
is OK, but i am left with "Zombie" images that no one points to
Any idea what is wrong?
Thanks
Report this post