Hi Vlad, thanks for your reply.
Your comment about the irregularity of interaction with the version attribute is 100% correct. However, we found a way to make it work.
In the use case for the described problem we use the version field in the way of:
1) get DTO from user
2) assemble entity from DTO, for the simplicity assume that we do:
Code:
Entity entity = new Entity();
entity.setId(...);
entity.setVersion(...); // <-- here we manually set version to a detached entity and it works as it should, although it's not mentioned as a recommended solution
em.saveAndFlush(entity);
In the described scenario, opt locks are working well, and we are able to pass\recieve version from a user. But the desired option is ability not to provide a version at all in some cases and still perform updates\deletes.
Maybe there is an elegant way to automatically set the latest version.