This content has been marked as final.
Show 2 replies
-
1. Re: ENTITY BEAN WITH SELF RELATIONSHIP
tinashechipomho May 16, 2006 5:47 PM (in response to sierras)I know you can do it in one direction but not both, I haven't been able to do it in both directions
say you have@Entity class Employee{ employeeno; name; .... mangerid; //managerid points to an existing employeeno in the same schema }
from the code above you can have the following relationship setup in one direction
Employee can get a Manager (another employee) but from a Manager Employee to get a list of his subordinates (possible by running the query below) is not straight forward:SELECT e FROM Employee e WHERE e.managerid=:currentemployeeid
to establish a self-referenced relationship tryclass Employee{ @Id employeeno; name; //....other properties... @ManyToOne @JoinColumn(name="managerid",referencedColumn="employeeno") managerid }
i have done this from memory, I will probably pull out me examples later on, and double check the @JoinColumn annotation I always get the name, and referencedname upside down -
2. Re: ENTITY BEAN WITH SELF RELATIONSHIP
epbernard May 18, 2006 2:30 PM (in response to sierras)@Entity
public class Employee {
@Id private Integer Id
@ManyToOne Employee manager;
@OneToMany(mappedBy="manager") Set team;