Versioning
Repository is an object responsible for storing entities states. It is used to find right objects and to store them for later use. Here I would like to show you how to implement a simple repository in Java using PostgreSQL database and JSONB type available there. The solution is very simple to implement. Although it has its weaknesses it is often the good enough one.
Optimistic locking is one of the concurrency control mechanisms. It can help avoid situations when one user overrides changes made by another one. When 2 users want to save the same object at the same time, we will reject one of them. The rejected user should review the new state of the object and decide if he still wants to do the update.