Search in sources :

Example 1 with NoResultException

use of jakarta.persistence.NoResultException in project spring-framework by spring-projects.

the class EntityManagerFactoryUtilsTests method testConvertJpaPersistenceException.

/*
	 * Test method for
	 * 'org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessException(PersistenceException)'
	 */
@Test
@SuppressWarnings("serial")
public void testConvertJpaPersistenceException() {
    EntityNotFoundException entityNotFound = new EntityNotFoundException();
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityNotFound).getClass()).isSameAs(JpaObjectRetrievalFailureException.class);
    NoResultException noResult = new NoResultException();
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(noResult).getClass()).isSameAs(EmptyResultDataAccessException.class);
    NonUniqueResultException nonUniqueResult = new NonUniqueResultException();
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass()).isSameAs(IncorrectResultSizeDataAccessException.class);
    OptimisticLockException optimisticLock = new OptimisticLockException();
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass()).isSameAs(JpaOptimisticLockingFailureException.class);
    EntityExistsException entityExists = new EntityExistsException("foo");
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityExists).getClass()).isSameAs(DataIntegrityViolationException.class);
    TransactionRequiredException transactionRequired = new TransactionRequiredException("foo");
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(transactionRequired).getClass()).isSameAs(InvalidDataAccessApiUsageException.class);
    PersistenceException unknown = new PersistenceException() {
    };
    assertThat(EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unknown).getClass()).isSameAs(JpaSystemException.class);
}
Also used : NonUniqueResultException(jakarta.persistence.NonUniqueResultException) TransactionRequiredException(jakarta.persistence.TransactionRequiredException) PersistenceException(jakarta.persistence.PersistenceException) OptimisticLockException(jakarta.persistence.OptimisticLockException) EntityNotFoundException(jakarta.persistence.EntityNotFoundException) NoResultException(jakarta.persistence.NoResultException) EntityExistsException(jakarta.persistence.EntityExistsException) Test(org.junit.jupiter.api.Test)

Aggregations

EntityExistsException (jakarta.persistence.EntityExistsException)1 EntityNotFoundException (jakarta.persistence.EntityNotFoundException)1 NoResultException (jakarta.persistence.NoResultException)1 NonUniqueResultException (jakarta.persistence.NonUniqueResultException)1 OptimisticLockException (jakarta.persistence.OptimisticLockException)1 PersistenceException (jakarta.persistence.PersistenceException)1 TransactionRequiredException (jakarta.persistence.TransactionRequiredException)1 Test (org.junit.jupiter.api.Test)1