Ultimately, I'm going to convert this to a Hibernate / JPA project. But I wanted to start with a pure database. We have different tables containing data that are dated in the future. Take the employee table with the following pseudo-definition:
employee
- id INT AUTO_INCREMENT
- ... data fields ...
- effectiveFrom DATE
- effectiveTo DATE
employee_reviews
- id INT AUTO_INCREMENT
- employee_id INT FK employee.id
Very simplified. But let them say that Employee A has id = 1, effectiveFrom = 1/1/2011, effectiveTo = 1/1/2099. This employee will change work in the future, which theoretically will create a new line, id = 2 with efficiency From = 7/1/2011, effectiveTo = 1/1/2099 and id = 1 effectiveTo updated to 6/30/2011. But now my program will have to go through any table that has an FK connection with an employee every night, and update these FK to refer to a new effective employee entry.
I have seen various publications on pure SQL and Hibernate forums that should have a separate employee_versions table in which I would contain all the data with effective dates, resulting in an updated pseudo-definition:
employee
employee_versions
- id INT AUTO_INCREMENT
- employee_id INT FK employee.id
- ... data fields ...
- effectiveFrom DATE
- effectiveTo DATE
employee_reviews
- id INT AUTO_INCREMENT
- employee_id INT FK employee.id
Then, in order to get any actual data, one would actually have to choose from employee_versions with the corresponding employee_id number and date. It looks rather unnatural to have this secondary "version" table for each object with a version.
Anyone have any opinions, suggestions from your own previous work, etc.? As I said, I take it purely from the general point of view of SQL design, first of all, before layering in Hibernate from above. Thanks!
source share