I've been learning JPA 2 and have learned about OneToMany and ManyToOne relationships. Here is my criteria.
- There are two entities, Employee and Feedback.
- An Employee can receive multiple feedbacks. i.e. there is ManyToOne relationship between a feedback and Employee. This I have achieved.
- But an Employee can also write multiple feedbacks for multiple employees. This is where I'm getting stuck.
I've build Employee to Feedback relationship as follows.
In Feedback class
@ManyToOne
@JoinColumn(name="idEmployee")
private Employee employee;
and in Employee class,
@OneToMany(mappedBy = "employee", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Feedback> feedbacks = new ArrayList<Feedback>();
now I can retrieve all feedbacks received for a employee. But an Employee can also give feedbacks to other employees. How can I achieve this relationship?
Do I need to use Map relationship? If yes, then why?