Hibernate and the four eyes pattern


I’m trying to implement a pattern in a system, which is called Four-Eyes, or Maker-Checker (More details about this pattern can be found here). I’ve found a demo implementation done using Envers.

The demo relies on Envers to make a helper table containing the history, but in my case, the history is not needed, just the ability to freeze a copy of a record while the same record is being changed.

Someone already have to implement such feature, or anything like it? I need some directions.

Thank you in advance.

You can have a maker property that references a User entity and a checker property as well.

You can use a custom FlushEntityEventListner to prevent modifications once the Document entity is signed by the maker or the checker.

You don’t need Envers to implement it if you don’t need the audit log table


If I understood you correctly, your proposal will only solve the approval part of this pattern. How can I deal with the “editing” copy of an entity? In my case, once a change is approved, a user can submit another change, but the unchanged (or the previous approved copy) of an entity must be able to be queried. In a given moment, it’ll be needed to have an editing copy and an approved copy. For this reason, in the example I’ve posted, Envers is used.

You can have a OneToMany association to store intermediary states. Document can have a parent id column for this purpose. Once the entity is frozen, only new child entities are accepted.

Is there any open source implementation of this pattern that you are aware of?

I don’t know. But if you can’t find any, you can write a Hibernate extension for it.