Versions in the optimized Hibernate lock

I am new to Hibernate and I am trying to understand @Version annotation. In all the examples, I saw that it looks like I have to provide a special column in each table of my database. I'm right? I understand what an optimistic lock is, but can I only do sleep mode, which is responsible for version control, and not change the database?

+3
source share
1 answer

You must add a column to the table if you want to use optimistic locking. Well, there is no need to add the version column to all tables for optimistic locking, if the child is accessible and modified using the entity parent, then you do not need to put the version column in the child's table.

Optimistic locking is a powerful feature of OR engines, it did not cause a loss of performance or deadlock, like a pessimistic locking of a database, so it should be preferred.

+6
source

Source: https://habr.com/ru/post/1794079/


All Articles