java - How to store single entity instead of collection? -
I need to create an institution that should store the history of my employee. Here is my table
create table worker_history (id INT not original primary key AUTO_INCREMENT, employee_id INT, company_id INT, hire_date DATE DEFAULT NULL, resign_date DATE DEFAULT Zero, foreign key (employee_id) reference worker (ID), foreign key (company_id) reference company (ID)); The problem is that I do not have a single entity employee history / <> code collection, collection & lt; Employee history & gt; needs to be archived. Any ideas how to solve this problem? UPD:
Result for Employee Mike:
1, Mike, Grid Dynamics, 2000-08-10, 2003-01-01 2, Mike, IBM, 2012-04-03, 2014-02-15 3, Mike, Grid Dynamics, 1997-04-17, 1998-03-08 UPD2:
My company unit class @inti @Table (name = "company") Public category company serializable {@Id @ Generated Value (strategy = Generation type. Et o) private integer ID; Name of the @column private string; @JoinColumn (name = "company_id") @OneToMany (fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JsonInclude (JsonInclude.Include.NON_NULL) @JsonProperty ("Employee") Private List & amp; Staff; & Staff; Employees; and employee category @tainty (name = "employee") public class employee serialjob {@Id @ Generated Values (String = Generation Type.Ato) @Jesonproporty ("ID") Integer ID; @column @ jesenproperty ("name") string name; @ManyToOne @JoinColumn (name = "company_id", nullable = true) @JsonInclude (JsonInclude.Include.NON_NULL) @Jasonproperty ("Company") Private Company Company; Keeping in mind that you have many history records related to an employee,
You can create a table named EMPLOYEE and now EMPLOYE_HISTORY Another table, named
Suppose that there are 5 records for an employee. / P>
You can create an entry in EMPLOYEE with employee details You can enter FK_EMPLOYEE in EMPLOYE_HISTORY Which will map all records in the history table to the unique employee entry in the EMPLOYEE table, and in this way you can get all 5 history records related to an employee.
Comments
Post a Comment