Search code examples
hibernatejpaoptimistic-locking

Precisely when is the version field updated on a versioned JPA entity?


I would like to know precisely when the field annotated with @Version is effectively incremented (and accessible with its incremented value) on the entity among the following processings :

  • entitymanager.flush() (triggered or not by commit)
  • before or after a @PreUpdate annotated callback method
  • before or after a @PostUpdate annotated callback method

Thank you


Solution

  • You can find the code that is executed during update in org.hibernate.action.internal.EntityUpdateAction#execute. The version in the object is updated after @PreUpdate and before @PostUpdate are called.