-
1. Re: How to do self ref. entities in EJB3
ycswyw Dec 4, 2005 2:57 PM (in response to ihunter)I think you should have to define the "JoinColumn" for the relations (to really setup the parent/childs in the same table) :
@Entity
public class ManagedObject {
@Id
@Column(name="ID")
public String getId() {
return dn;
}
public void setId(String dn) {
this.dn = dn;
}
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name="PARENT")
public Collection getChildren() {
return children;
}
public void setChildren(Collection children) {
this.children = children;
}
@ManyToOne
@JoinColumn(name="PARENT")
public ManagedObject getParent() {
return parent;
}
public void setParent(ManagedObject parent) {
this.parent = parent;
}
private Collection children;
private ManagedObject parent;
private String dn;
}
And then, you can directly delete the parent with "entityManager.remove(parent)"
(without setting parent.setChildren(null) nor setParent(null) on all children). -
2. Re: How to do self ref. entities in EJB3
ihunter Dec 5, 2005 3:59 AM (in response to ihunter)Thanks Mr/Ms. ycswyw - thats done the job.
Ian