Entity Relationships
  • One-to-One
One-to-One Example  
  • One-to-Many
One-to-Many Example  
  • Many-to-Many
Many-to-Many Example  
  @Entity
  public class Employee {
    ...
    @ManyToMany(mappedBy="employees") // Manager is the "owner"
    public Set<Manager> getManagers() {
        return managers;
    }
    ...
  }

  @Entity
  public class Manager {
    ...
    @ManyToMany
    public Set<Employee> getEmployees() {
        return employees;
    }
    ...
  }