I have so many tables that need to store historical data inside. Each time some column get changed, the row will be cloned and a new verion number is assigned to it. Different versions of rows exist together in the same table. Moreover, tables have one-to-many or many-to-many relationships. For example:
Code:
Parent table:
Parent system Id parent id name version
1 1 abc 1
2 1 abcd 2
Child table:
Child system id child id name version parent id
1 1 xyz 1 1
2 1 xy 2 1
Every time the name get changed, a new version will be created. The id will be the same and the system id is new (generated using sequence). Version get increased. Also, in each table, there are effective date and end date columns to indicate the valid period of the row.
In this case, if I do a one-to-many mapping from parent to child table. It will return me all the children records. But most of the time I just need one, which is determined by the date I pass (effective date <= date <= end date). The same for the case from child to get parent.
It seems that Hibernate doesn't support this kind of data fetching. Currently I have to manually write query to search for the specific child record and construct the object graph by myself. Is there any better way to do that?
Code: