Here are the examples of the java api org.hibernate.StaleObjectStateException taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : ExceptionConverterImpl.java
with GNU General Public License v2.0
from lamsfoundation
with GNU General Public License v2.0
from lamsfoundation
protected PersistenceException wrapStaleStateException(StaleStateException e) {
PersistenceException pe;
if (e instanceof StaleObjectStateException) {
final StaleObjectStateException sose = (StaleObjectStateException) e;
final Serializable identifier = sose.getIdentifier();
if (identifier != null) {
try {
final Object enreplacedy = sharedSessionContract.internalLoad(sose.getEnreplacedyName(), identifier, false, true);
if (enreplacedy instanceof Serializable) {
// avoid some user errors regarding boundary crossing
pe = new OptimisticLockException(e.getMessage(), e, enreplacedy);
} else {
pe = new OptimisticLockException(e.getMessage(), e);
}
} catch (EnreplacedyNotFoundException enfe) {
pe = new OptimisticLockException(e.getMessage(), e);
}
} else {
pe = new OptimisticLockException(e.getMessage(), e);
}
} else {
pe = new OptimisticLockException(e.getMessage(), e);
}
return pe;
}
13
Source : HibernateJpaDialect.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Convert the given HibernateException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy.
* @param ex HibernateException that occurred
* @return the corresponding DataAccessException instance
*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof SQLGrammarException) {
SQLGrammarException jdbcEx = (SQLGrammarException) ex;
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof QueryTimeoutException) {
QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof LockAcquisitionException) {
LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof PessimisticLockException) {
PessimisticLockException jdbcEx = (PessimisticLockException) ex;
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof ConstraintViolationException) {
ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
}
if (ex instanceof DataException) {
DataException jdbcEx = (DataException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
// end of JDBCException subclreplaced handling
if (ex instanceof QueryException) {
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof NonUniqueObjectException) {
return new DuplicateKeyException(ex.getMessage(), ex);
}
if (ex instanceof PropertyValueException) {
return new DataIntegrityViolationException(ex.getMessage(), ex);
}
if (ex instanceof PersistentObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof TransientObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof ObjectDeletedException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof UnresolvableObjectException) {
UnresolvableObjectException hibEx = (UnresolvableObjectException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof WrongClreplacedException) {
WrongClreplacedException hibEx = (WrongClreplacedException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof StaleObjectStateException) {
StaleObjectStateException hibEx = (StaleObjectStateException) ex;
return new ObjectOptimisticLockingFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex);
}
if (ex instanceof StaleStateException) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (optimisticLockExceptionClreplaced.isInstance(ex)) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (pessimisticLockExceptionClreplaced != null && pessimisticLockExceptionClreplaced.isInstance(ex)) {
if (ex.getCause() instanceof LockAcquisitionException) {
return new CannotAcquireLockException(ex.getMessage(), ex.getCause());
}
return new PessimisticLockingFailureException(ex.getMessage(), ex);
}
// fallback
return new JpaSystemException(ex);
}
9
Source : HibernateJpaDialect.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Convert the given HibernateException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy.
* @param ex the HibernateException that occurred
* @return the corresponding DataAccessException instance
*/
protected DataAccessException convertHibernateAccessException(HibernateException ex) {
if (this.jdbcExceptionTranslator != null && ex instanceof JDBCException) {
JDBCException jdbcEx = (JDBCException) ex;
DataAccessException dae = this.jdbcExceptionTranslator.translate("Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException());
if (dae != null) {
throw dae;
}
}
if (ex instanceof JDBCConnectionException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof SQLGrammarException) {
SQLGrammarException jdbcEx = (SQLGrammarException) ex;
return new InvalidDataAccessResourceUsageException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof QueryTimeoutException) {
QueryTimeoutException jdbcEx = (QueryTimeoutException) ex;
return new org.springframework.dao.QueryTimeoutException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof LockAcquisitionException) {
LockAcquisitionException jdbcEx = (LockAcquisitionException) ex;
return new CannotAcquireLockException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof PessimisticLockException) {
PessimisticLockException jdbcEx = (PessimisticLockException) ex;
return new PessimisticLockingFailureException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
if (ex instanceof ConstraintViolationException) {
ConstraintViolationException jdbcEx = (ConstraintViolationException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]; constraint [" + jdbcEx.getConstraintName() + "]", ex);
}
if (ex instanceof DataException) {
DataException jdbcEx = (DataException) ex;
return new DataIntegrityViolationException(ex.getMessage() + "; SQL [" + jdbcEx.getSQL() + "]", ex);
}
// end of JDBCException subclreplaced handling
if (ex instanceof QueryException) {
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof NonUniqueObjectException) {
return new DuplicateKeyException(ex.getMessage(), ex);
}
if (ex instanceof PropertyValueException) {
return new DataIntegrityViolationException(ex.getMessage(), ex);
}
if (ex instanceof PersistentObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof TransientObjectException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof ObjectDeletedException) {
return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
}
if (ex instanceof UnresolvableObjectException) {
UnresolvableObjectException hibEx = (UnresolvableObjectException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof WrongClreplacedException) {
WrongClreplacedException hibEx = (WrongClreplacedException) ex;
return new ObjectRetrievalFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex.getMessage(), ex);
}
if (ex instanceof StaleObjectStateException) {
StaleObjectStateException hibEx = (StaleObjectStateException) ex;
return new ObjectOptimisticLockingFailureException(hibEx.getEnreplacedyName(), hibEx.getIdentifier(), ex);
}
if (ex instanceof StaleStateException) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (ex instanceof OptimisticEnreplacedyLockException) {
return new ObjectOptimisticLockingFailureException(ex.getMessage(), ex);
}
if (ex instanceof PessimisticEnreplacedyLockException) {
if (ex.getCause() instanceof LockAcquisitionException) {
return new CannotAcquireLockException(ex.getMessage(), ex.getCause());
}
return new PessimisticLockingFailureException(ex.getMessage(), ex);
}
// fallback
return new JpaSystemException(ex);
}