@Cacheable
@Cache(usage = TRANSACTIONAL)
public class MyEntity() {
@Id private Long id;
@Version private Long version;
}
MyEntity entity = entityManager.find(MyEntity.class, 1L, LockModeType.OPTIMISTIC_FORCE_INCREMENT);
System.out.println(entity.getVersion());
...
MyEntity entity = entityManager.find(MyEntity.class, 1L);
System.out.println(entity.getVersion());
If cache usage is TRANSACTIONAL, the second find() will find the entity with version=0. If cache usage is any other (READ_WRITE for example), the second find() will return the entity with version=1 (which is correct).
The reason of this behaviour is in TransactionalEhcacheEntityRegionAccessStrategy.putFromLoad. It does not check that the entity is stale and must NOT be cached in the cache. The same behaviour applies to Infinispan cache implementation.
|