| @Gail Badner, testOptimisticLockException_Flush_LocalV0_CacheV0_DBV1 is similar to the one provided by @Tom Dearman, but introduce a second entity to demonstrate that an OptimisticLockException invalidate not only the state entity but all the entities involved. In that example, both like below before the catch get cache hit (not going to db)
Employee emp2 = session2.get(Employee.class, 1);
Manager mana2 = session2.get(Manager.class, 1);
Then as expected due to hacking on DB side of Manager we get an OptimisticLockException. Then in the catch, we demonstrate with a Employee, which was not stale, that it got invalidated. We see it hit the database, we should have a cache hit if the invalidation algorithm was optimized. The rest of the code in the catch block demonstrate that Manager have been invalidated, which is good. |