I would like to know how to implement temporal tables in JPA 2 with EclipseLink. By temporal I mean tables who define validity period.
One problem that I\'m facing is t
in DAO Fusion, tracking an entity in both timelines (validity and record interval) is realized by wrapping that entity by BitemporalWrapper
.
The bitemporal reference documentation presents an example with regular Order
entity being wrapped by BitemporalOrder
entity. BitemporalOrder
maps to a separate database table, with columns for validity and record interval, and foreign key reference to Order
(via @ManyToOne
), for each table row.
The documentation also indicates that each bitemporal wrapper (e.g. BitemporalOrder
) represents one item within the bitemporal record chain. Therefore, you need some higher-level entity that contains bitemporal wrapper collection, e.g. Customer
entity which contains @OneToMany Collection
.
So, if you need a "logical child" entity (e.g. Order
or Player
) to be bitemporally tracked, and its "logical parent" entity (e.g. Customer
or Team
) to be bitemporally tracked as well, you need to provide bitemporal wrappers for both. You will have BitemporalPlayer
and BitemporalTeam
. BitemporalTeam
can declare @OneToMany Collection
. But you need some higher-level entity for containing @OneToMany Collection
, as mentioned above. For
example, you could create a Game
entity that contains BitemporalTeam
collection.
However, if you don't need record interval and you just need validity interval (e.g. not bitemporal, but uni-temporal tracking of your entities), your best bet is to roll your own custom implementation.