I am using JPA + hibernate + Spring, but looks like the Cascade doesn't work.
Please see the coding, what I expect is, "John" is deleted, "Mary" is added. But I try all javax.persistence.CascadeType, it will not give me the result. Then I try to use org.hibernate.annotations.CascadeType, it will always give me syntax error.
Where is the problem ?
Thanks.
Code:
class Company{
....
@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = FetchType.EAGER)
List<Employee> employeeList;
}
// test coding
Company company = new Company();
List<Employee> employeeList = new ArrayList<Employee>();
employeeList.add(new Empployee("John"));
employeeList.add(new Empployee("Peter"));
company.setEmployeeList(employeeList);
dao.getHibernateTemplate().merge(company);
//-------------
company.getEmployeeList().remove(0);
company.getEmployeeList().add(new Employee("Mary"));
dao.getHibernateTemplate().merge(company);
// what I expect is, "John" is deleted, "Mary" is added.