Archive

Posts Tagged ‘locking’

JPA locking techniques

30/03/2011 1 comment

Recently I found out that there are some misunderstandings regarding locking entities with JPA 2. With this post I intend to summarize the locking techniques used by JPA.

The first version of the JPA specification only supported optimistic locking. Optimistic locking insures that entity state updates are made only when the entity’s state is not updated since its state was read. To apply optimistic locking on an entity, it must declare a version attribute. With optimistic locking the entity’s state is being checked when flushing the changes of the EntityManager, rolling back changes when the entity’s state was changed by an intervening transaction.

JPA 2 supports both optimistic and pessimistic locking. Read more…

Categories: Java Tags: ,