@Test public void testExplicitOptimisticLocking() throws InterruptedException { try { doInJPA(entityManager -> { try { final Post post = entityManager.find(Post.class, 1L, LockModeType.OPTIMISTIC); PostComment comment = new PostComment(); comment.setId(1L); comment.setReview("Good one."); comment.setPost(post); lockUpgrade(entityManager, post); ready.set(true); } catch (Exception e) { throw new IllegalStateException(e); } }); } catch (OptimisticEntityLockException expected) { LOGGER.info("Failure: ", expected); } endLatch.await(); }
@Test public void testExplicitOptimisticLocking() { try { doInTransaction(session -> { final Product product = (Product) session.get(Product.class, 1L, new LockOptions(LockMode.OPTIMISTIC)); executeSync(() -> { doInTransaction(_session -> { Product _product = (Product) _session.get(Product.class, 1L); assertNotSame(product, _product); _product.setPrice(BigDecimal.valueOf(14.49)); }); }); OrderLine orderLine = new OrderLine(product); session.persist(orderLine); }); fail("It should have thrown OptimisticEntityLockException!"); } catch (OptimisticEntityLockException expected) { LOGGER.info("Failure: ", expected); } }
@Test public void testExplicitOptimisticLocking() throws InterruptedException { try { doInTransaction(session -> { try { final Product product = (Product) session.get(Product.class, 1L, new LockOptions(LockMode.OPTIMISTIC)); OrderLine orderLine = new OrderLine(product); session.persist(orderLine); lockUpgrade(session, product); ready.set(true); } catch (Exception e) { throw new IllegalStateException(e); } }); } catch (OptimisticEntityLockException expected) { LOGGER.info("Failure: ", expected); } endLatch.await(); }
public HibernateOptimisticLockingFailureException(OptimisticEntityLockException ex) { super(ex.getMessage(), ex); }