-
1. Re: difference between @Version and EntityManager.lock
waynebaylor Jun 9, 2007 8:38 PM (in response to adamzrk)The OptimisticLockException indicates that the second client has a stale version of the entity, i.e. it won't be updating the latest version.
As far as I know, using the EntityManager.lock method will force the version to be incremented, whether or not you actually changed the entity. -
2. Re: difference between @Version and EntityManager.lock
adamzrk Jun 10, 2007 6:03 AM (in response to adamzrk)So, i guess, when using only version without lock there won't be increment of version attribute? Is it possible? I thought that version is always incremented after update.
-
3. Re: difference between @Version and EntityManager.lock
alrubinger Jun 10, 2007 9:36 AM (in response to adamzrk)@Version will enable JPA Optmistic locking for the entity. EM.lock allows the application to specify the lock mode to be used on the versioned object.
http://java.sun.com/javaee/5/docs/api/javax/persistence/LockModeType.html
This is no JPA "waiting" or caching of updates to an entity until another Tx is finished with it; that responsibility is on the part of the application. JPA locking provides you with a mechinism to ensure your data integrity is kept.
S,
ALR