Java 类org.hibernate.dialect.lock.OptimisticEntityLockException 实例源码

项目:high-performance-java-persistence    文件:LockModeOptimisticRaceConditionTest.java   
@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();
}
项目:hibernate-master-class    文件:LockModeOptimisticTest.java   
@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);
    }
}
项目:hibernate-master-class    文件:LockModeOptimisticRaceConditionTest.java   
@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();
}
项目:lams    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(OptimisticEntityLockException ex) {
    super(ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(OptimisticEntityLockException ex) {
    super(ex.getMessage(), ex);
}
项目:spring4-understanding    文件:HibernateOptimisticLockingFailureException.java   
public HibernateOptimisticLockingFailureException(OptimisticEntityLockException ex) {
    super(ex.getMessage(), ex);
}