title: What is the best way to map data of junction table in Java entity?
body: <p>I have three tables which presents my very simple project.</p>
  
  <pre><code>CREATE TABLE company (
    id   INT          NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(250) NOT NULL
  );
  
  CREATE TABLE employee (
    id   INT          NOT NULL PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(250) NOT NULL
  );
  
  CREATE TABLE company_employee (
    company_id  INT NOT NULL,
    employee_id INT NOT NULL,
    hire_date   DATE DEFAULT NULL,
    resign_date DATE DEFAULT NULL,
    FOREIGN KEY (company_id) REFERENCES company (id),
    FOREIGN KEY (employee_id) REFERENCES employee (id)
  );
  </code></pre>
  
  <p>And I have Java representation</p>
  
  <pre><code>@Entity
  @Table(name = "employee")
  public class Employee implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      Integer id;
  
      @Column(name = "name")
      String name;
  
      @ManyToMany(mappedBy = "employees")
      private List&lt;Company&gt; companies;
  
  
  @Entity
  @Table(name = "company")
  public class Company implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      @Column(name = "name")
      private String name;
  
      @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      @JoinTable(name = "company_employee",
                 joinColumns = {@JoinColumn(name = "company_id")},
                 inverseJoinColumns = {@JoinColumn(name = "employee_id")})
      private Collection&lt;Employee&gt; employees;
  </code></pre>
  
  <p>I can't figured out where I can store history data. In history data I need to store hire_date, resign_date of emplyee and to store all companies of each emplyee as well. So my question is haw can I manage such infortation and what is the best way to store all that history info?</p>