Entity Relationships
  • One-to-One
One-to-One Example  
  • One-to-Many
One-to-Many Example  
  @Entity
  public class Department {
    ...
    @OneToMany(mappedBy="department") // Employee is the "owner"
    public Set<Employee> getEmployees() {
        return employees;
    }
    ...
  }

  @Entity
  public class Employee {
    ...
    @ManyToOne
    public Department getDepartment() {
        return department;
    }
    ...
  }
  • Many-to-Many
Many-to-Many Example