Hibernate version: 3.2
Database : mySql 5.0.24a
Hi All,
In my project I have a one-to-many relationship. Here is the sample code.
class School{
@OneToMany(cascade = CascadeType.ALL, mappedBy = ("school"))
public Set<Student> getStudents() {
return students;
}
}
class Student{
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = ("SchoolId"), nullable = false, unique = false)
public School getSchool() {
return school;
}
}
The question is : I want to delete all the students of a school when the school is deleted. In other words I want to make it delete on cascade. I am using hibernate3-maven-plugin to create the database and it uses hibernate to create the database. When I set the delete on cascade It works but I try to define it in the annotations.
Thanks in advance.
|