[jboss-user] [EJB 3.0] - How to cause related entities to update when base entity is

A_titov82 do-not-reply at jboss.com
Tue Sep 19 16:15:30 EDT 2006


I have two entities:

public class Employee {
  | ...
  | 	@ManyToOne
  | 	public Organization getPlaceOfWork() {
  | 		return placeOfWork;
  | 	}
  | 	public void setPlaceOfWork(Organization placeOfWork) {
  | 		this.placeOfWork = placeOfWork;
  | 		if(placeOfWork!=null){
  | 			placeOfWork.getEmployees().add(this);
  | 		}
  | 	}
  | 	
  | }
  | 
  | public class Organization  {
  | ...
  | 	@OneToMany(fetch=FetchType.EAGER, mappedBy="placeOfWork")
  | 	public Collection<Employee> getEmployees() {
  | 		return employees;
  | 	}
  | 	public void setEmployees(Collection<Employee> employees) {
  | 		this.employees = employees;
  | 	}
  | }
How can I cause Employees to be set their placeOfWork to null when Organization is removed (like database cascade)? And what should I do, if I want to delete Employees when Organization is removed?

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972723#3972723

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972723



More information about the jboss-user mailing list