当前位置: 首页>>代码示例>>Java>>正文


Java StaleObjectStateException类代码示例

本文整理汇总了Java中org.hibernate.StaleObjectStateException的典型用法代码示例。如果您正苦于以下问题:Java StaleObjectStateException类的具体用法?Java StaleObjectStateException怎么用?Java StaleObjectStateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StaleObjectStateException类属于org.hibernate包,在下文中一共展示了StaleObjectStateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleException

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
private void handleException(Throwable e)
        throws VmidcDbConstraintViolationException, VmidcDbConcurrencyException, Exception {
    if (e instanceof SslCertificatesExtendedException) {
        throw (SslCertificatesExtendedException) e;
    } else if (e instanceof VmidcException) {
        log.warn("Service request failed (logically): " + e.getMessage());
    } else {
        log.error("Service request failed (unexpectedly): " + e.getMessage(), e);
    }

    if (e instanceof ConstraintViolationException) {
        log.error("Got database constraint violation exception", e);

        throw new VmidcDbConstraintViolationException("Database Constraint Violation Exception.");

    } else if (e instanceof StaleObjectStateException) {
        log.error("Got database concurrency exception", e);

        throw new VmidcDbConcurrencyException("Database Concurrency Exception.");
    } else if (e instanceof Exception) {
        throw (Exception) e;
    }


    throw new Exception("Exception or error executing service call: " + e.getMessage(), e);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:27,代码来源:ServiceDispatcher.java

示例2: doFilter

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
public void doFilter(ServletRequest request,
                     ServletResponse response,
                     FilterChain chain)
        throws IOException, ServletException {

    try {

        sf.getCurrentSession().beginTransaction();
        chain.doFilter(request, response);
        sf.getCurrentSession().getTransaction().commit();

    } catch (StaleObjectStateException staleEx) {
        throw staleEx;
    } catch (Throwable ex) {
        // Rollback only
        ex.printStackTrace();
        try {
            if (sf.getCurrentSession().getTransaction().isActive()) {
                sf.getCurrentSession().getTransaction().rollback();
            }
        } catch (Throwable rbEx) {
        		System.out.print(rbEx.getStackTrace());
        }
        throw new ServletException(ex);
    }
}
 
开发者ID:giuseppeurso-eu,项目名称:struts-mvc,代码行数:27,代码来源:SessionRequestFilter.java

示例3: getDatabaseSnapshot

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
	if ( persister.isSelectBeforeUpdateRequired() ) {
		Object[] snapshot = session.getPersistenceContext()
				.getDatabaseSnapshot( id, persister );
		if ( snapshot == null ) {
			//do we even really need this? the update will fail anyway....
			if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
				session.getFactory().getStatisticsImplementor()
						.optimisticFailure( persister.getEntityName() );
			}
			throw new StaleObjectStateException( persister.getEntityName(), id );
		}
		return snapshot;
	}
	// TODO: optimize away this lookup for entities w/o unsaved-value="undefined"
	final EntityKey entityKey = session.generateEntityKey( id, persister );
	return session.getPersistenceContext().getCachedDatabaseSnapshot( entityKey );
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:DefaultFlushEntityEventListener.java

示例4: execute

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Override
public void execute() {
	Transaction tx = session.beginTransaction();
	try{
		if (primerak != null)
			session.update(primerak);
		if (lending != null)
			session.update(lending);
		tx.commit();
		if (lending != null){
			log.info("discharging book successfully: "+ lending.getCtlgNo());
		} else {
			log.info("discharging book successfully: ");
		}
		success = true;
	}catch (StaleObjectStateException e){
   		tx.rollback();
   		if (lending != null){
			log.info("discharging book failed: "+ lending.getCtlgNo());
		} else {
			log.info("discharging book failed: ");
		}
   		log.error(e);
   		message = e.getMessage();
	}
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:27,代码来源:DischargeBookCommand.java

示例5: getDatabaseSnapshot

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
private Object[] getDatabaseSnapshot(SessionImplementor session, EntityPersister persister, Serializable id) {
	if ( persister.isSelectBeforeUpdateRequired() ) {
		Object[] snapshot = session.getPersistenceContext()
				.getDatabaseSnapshot(id, persister);
		if (snapshot==null) {
			//do we even really need this? the update will fail anyway....
			if ( session.getFactory().getStatistics().isStatisticsEnabled() ) {
				session.getFactory().getStatisticsImplementor()
						.optimisticFailure( persister.getEntityName() );
			}
			throw new StaleObjectStateException( persister.getEntityName(), id );
		}
		else {
			return snapshot;
		}
	}
	else {
		//TODO: optimize away this lookup for entities w/o unsaved-value="undefined"
		EntityKey entityKey = new EntityKey( id, persister, session.getEntityMode() );
		return session.getPersistenceContext()
				.getCachedDatabaseSnapshot( entityKey ); 
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:DefaultFlushEntityEventListener.java

示例6: save

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
/**
 * (non-Javadoc)
 * 
 * @see architecture.hibernate.DataAccess#save(java.lang.Object)
 * also starts a transaction, if none is active
 */
@Override
public boolean save(T obj) {
    Session s = dbAccess.getActiveSession();
    try {
            s.saveOrUpdate(obj);
            return true;
    } catch (StaleObjectStateException stex) {
            s.refresh(obj);
            return false;
    } catch (RuntimeException rex) {
            Transaction t = s.getTransaction();
            if (t != null) {
                    t.rollback();
            }
            s.close();
            throw rex;
    }
}
 
开发者ID:R3d-Dragon,项目名称:jMovieManager,代码行数:25,代码来源:DaoImpl.java

示例7: run

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Override
public void run() {
    try {
        doInJPA(entityManager -> {
            try {
                Post post = entityManager.find(Post.class, 1L);
                loadPostLatch.countDown();
                loadPostLatch.await();
                post.setTitle("JPA");
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        });
    } catch (StaleObjectStateException expected) {
        LOGGER.info("Alice: Optimistic locking failure", expected);
    }
    aliceLatch.countDown();
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:19,代码来源:OptimisticLockingOneRootOneVersionTest.java

示例8: testPessimisticLocking

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
private void testPessimisticLocking(LockRequestCallable primaryLockRequestCallable, LockRequestCallable secondaryLockRequestCallable) {
    doInJPA(entityManager -> {
        try {
            Session session = entityManager.unwrap(Session.class);
            Post post = entityManager.find(Post.class, 1L);
            primaryLockRequestCallable.lock(session, post);
            executeAsync(
                    () -> {
                        doInJPA(_entityManager -> {
                            Session _session = _entityManager.unwrap(Session.class);
                            Post _post = _entityManager.find(Post.class, 1L);
                            secondaryLockRequestCallable.lock(_session, _post);
                        });
                    },
                    endLatch::countDown
            );
            sleep(WAIT_MILLIS);
        } catch (StaleObjectStateException e) {
            LOGGER.info("Optimistic locking failure: ", e);
        }
    });
    awaitOnLatch(endLatch);
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:24,代码来源:LockModePessimisticReadWriteIntegrationTest.java

示例9: run

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Override
public void run() {
    try {
        doInJPA(entityManager -> {
            try {
                entityManager.unwrap(Session.class).doWork(connection -> {
                    assertEquals(Connection.TRANSACTION_REPEATABLE_READ, connection.getTransactionIsolation());
                });

                Post post = entityManager.find(Post.class, 1L);
                loadPostLatch.countDown();
                loadPostLatch.await();
                post.setTitle("JPA");
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        });
    } catch (StaleObjectStateException expected) {
        LOGGER.info("Alice: Optimistic locking failure", expected);
    } catch (Exception unexpected) {
        LOGGER.info("Alice: Optimistic locking failure due to MVCC", unexpected);
    }
    aliceLatch.countDown();
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:25,代码来源:OptimisticLockingRepeatableReadTest.java

示例10: testConcurrentPessimisticForceIncrementLockingFailFast

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Test
public void testConcurrentPessimisticForceIncrementLockingFailFast() {
    try {
        doInJPA(entityManager -> {
            Repository repository = entityManager.find(Repository.class, 1L);

            executeSync(() -> {
                doInJPA(_entityManager -> {
                    Repository _repository = _entityManager.find(Repository.class, 1L,
                        LockModeType.PESSIMISTIC_FORCE_INCREMENT);

                    Commit _commit = new Commit(_repository);
                    _commit.getChanges().add(new Change("Intro.md", "0a1,2..."));

                    _entityManager.persist(_commit);
                });
            });

            entityManager.lock(repository, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
            fail("Should have thrown StaleObjectStateException!");
        });
    } catch (OptimisticLockException expected) {
        assertEquals(StaleObjectStateException.class, expected.getCause().getClass());
        LOGGER.info("Failure: ", expected);
    }
}
 
开发者ID:vladmihalcea,项目名称:high-performance-java-persistence,代码行数:27,代码来源:LockModePessimisticForceIncrementTest.java

示例11: deleteBusinessGroup

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
/**
*/
  @Override
  public void deleteBusinessGroup(BusinessGroup businessGroupTodelete) {
      try {
          // Delete the group object itself on the database
          db.deleteObject(businessGroupTodelete);
      } catch (final DBRuntimeException dbre) {
          final Throwable th = dbre.getCause();
          if ((th instanceof StaleObjectStateException) && (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) {
              // known issue OLAT-3654
              log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654");
              throw new KnownIssueException("Group was deleted by another user in the meantime", 3654);
          } else {
              throw dbre;
          }
      }
  }
 
开发者ID:huihoo,项目名称:olat,代码行数:19,代码来源:BusinessGroupDaoImpl.java

示例12: deleteBusinessGroup

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
/**
*/
  @Override
  public void deleteBusinessGroup(BusinessGroup businessGroupTodelete) {
      try {
          // Delete the group object itself on the database
          db.deleteObject(businessGroupTodelete);
      } catch (final DBRuntimeException dbre) {
          final Throwable th = dbre.getCause();
          if ((th instanceof StaleObjectStateException) && (th.getMessage().startsWith("Row was updated or deleted by another transaction"))) {
              // known issue OLAT-3654
              log.info("Group was deleted by another user in the meantime. Known issue OLAT-3654");
              throw new KnownIssueException("Group was deleted by another user in the meantime", 3654, dbre);
          } else {
              throw dbre;
          }
      }
  }
 
开发者ID:huihoo,项目名称:olat,代码行数:19,代码来源:BusinessGroupDaoImpl.java

示例13: run

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Override
public void run() {
    try {
        doInTransaction(session -> {
            try {
                Product product = (Product) session.get(Product.class, 1L);
                loadProductsLatch.countDown();
                loadProductsLatch.await();
                product.setQuantity(6L);
            } catch (InterruptedException e) {
                throw new IllegalStateException(e);
            }
        });
    } catch (StaleObjectStateException expected) {
        LOGGER.info("Alice: Optimistic locking failure", expected);
    }
    aliceLatch.countDown();
}
 
开发者ID:vladmihalcea,项目名称:hibernate-master-class,代码行数:19,代码来源:OptimisticLockingOneRootOneVersionTest.java

示例14: testPessimisticLocking

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
private void testPessimisticLocking(ProductLockRequestCallable primaryLockRequestCallable, ProductLockRequestCallable secondaryLockRequestCallable) {
    doInTransaction(session -> {
        try {
            Product product = (Product) session.get(Product.class, 1L);
            primaryLockRequestCallable.lock(session, product);
            executeAsync(
                    () -> {
                        doInTransaction(_session -> {
                            Product _product = (Product) _session.get(Product.class, 1L);
                            secondaryLockRequestCallable.lock(_session, _product);
                        });
                    },
                    endLatch::countDown
            );
            sleep(WAIT_MILLIS);
        } catch (StaleObjectStateException e) {
            LOGGER.info("Optimistic locking failure: ", e);
        }
    });
    awaitOnLatch(endLatch);
}
 
开发者ID:vladmihalcea,项目名称:hibernate-master-class,代码行数:22,代码来源:LockModePessimisticReadWriteIntegrationTest.java

示例15: testConcurrentPessimisticForceIncrementLockingFailFast

import org.hibernate.StaleObjectStateException; //导入依赖的package包/类
@Test
public void testConcurrentPessimisticForceIncrementLockingFailFast() throws InterruptedException {
    LOGGER.info("Test Concurrent PESSIMISTIC_FORCE_INCREMENT Lock Mode fail fast");
    doInTransaction(session -> {
        try {
            Repository repository = (Repository) session.get(Repository.class, 1L);

            executeSync(() -> {
                doInTransaction(_session -> {
                    Repository _repository = (Repository) _session.get(Repository.class, 1L);
                    _session.buildLockRequest(new LockOptions(LockMode.PESSIMISTIC_FORCE_INCREMENT)).lock(_repository);
                    Commit _commit = new Commit(_repository);
                    _commit.getChanges().add(new Change("index.html", "0a1,2..."));
                    _session.persist(_commit);
                    _session.flush();
                });
            });
            session.buildLockRequest(new LockOptions(LockMode.PESSIMISTIC_FORCE_INCREMENT)).lock(repository);
            fail("Should have thrown StaleObjectStateException!");
        } catch (StaleObjectStateException expected) {
            LOGGER.info("Failure: ", expected);
        }
    });
}
 
开发者ID:vladmihalcea,项目名称:hibernate-master-class,代码行数:25,代码来源:LockModePessimisticForceIncrementTest.java


注:本文中的org.hibernate.StaleObjectStateException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。