I need to create a model in which changes to entities (essentially a transaction) need to be persisted separately and go through a process of approval (by other users) before being actually applied.
Think of it as creating a branch in Git (representing a transaction in JPA/Hibernate) and requesting it to be merged to be back. A desir(ed|able) side-effect of this is that this also covers auditing - as the history will be present already, but note that this is NOT the primary reason for the question (that would be addressed by something like Envers, for example).
Most of the entities can participate in this and I would like to avoid duplicating everything in order to have the "official entity" separate from "staging entities" or similar. Staging would need to cover inserts, updates and deletes (perhaps using tombstones).
I am trying to simplify this for most of the development and push as much of this out to Hibernate / 3rd party libraries and, if not there, to a framework that I would have to create. Ideally all regular transaction commits would actually be against the staging areas (potentially create it) - the only exception would be the final / apply action, which may be treated specially.
One of the main challenges for me is dealing with the fact that normal use of entities and their ids (primary keys) will point to the sole/master copy of the entity - I don't know how to redirect those elsewhere.
Does anyone have any suggestions?