I am about to start implementing the following relationship:
Entity one-to-many Configuration
But the Configuration
will evolve over time, including the creation of future Configuration
s, meaning the following fields in the configuration
table:
entityId
fromDate
toDate
configurationValue1
configurationValue2
...
fromDate
and the toDate
store the dates when a particular version of the information is active.
The final entry in the configuration
table would have its fromDate
, and a very distant toDate
. Adding a new Configuration
before the toDate
would update the current latest configuration to have an toDate
the day before the new configuration's fromDate
, and the new Configuration
's toDate
would be the value in the future.
All this seems like a good case for a well-defined and tested DAO able to retrieve all Configuration
s for an Entity
, the current Configuration
for an Entity
, and to update future Configuration
s (ensuring no overlap of dates of course), but before I go about implementing it, is there anything within Hibernate that would help, for example, code that could allow me to do this? :
myEntity.getCurrentConfiguration() //perhaps a @Where that uses now() to find the correct Configuration?
I am aware of Hibernate Envers but I don't think that this is necessarily the right use case for it. Envers seems to manage audit logs, transparently keeping a history of changes made to an entity, whereas I want to be able to manage the current and future values of an entity, with the current value being based upon now()
(I do however need to be able to keep all old entries).