Hi, i have a association oneToMany
One Corso have many Lezioni. I write:
Code:
public class Corso{
...
@OneToMany(mappedBy="corso")
@Cascade(value={CascadeType.SAVE_UPDATE,CascadeType.DELETE})
private Collection<Lezione> lezione=new ArrayList<Lezione>();
...
}
in class Lezione:
Code:
public class Lezione{
...
@ManyToOne
@JoinColumn(name = "ID_CORSO", nullable = false)
private Corso corso;
...
}
In dao i write:
Code:
getHibernateTemplate().delete(corso);
I tried to cancel a course a Corso, but I get the error:
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/project] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]; nested exception is org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]] with root cause
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [org.rol.pojo.Lezione#4]
why?
I if I delete a course I want to delete the lessons associated