@Test @SuppressWarnings("serial") public void testConvertJpaPersistenceException() { EntityNotFoundException entityNotFound = new EntityNotFoundException(); assertSame(JpaObjectRetrievalFailureException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityNotFound).getClass()); NoResultException noResult = new NoResultException(); assertSame(EmptyResultDataAccessException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(noResult).getClass()); NonUniqueResultException nonUniqueResult = new NonUniqueResultException(); assertSame(IncorrectResultSizeDataAccessException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass()); OptimisticLockException optimisticLock = new OptimisticLockException(); assertSame(JpaOptimisticLockingFailureException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass()); EntityExistsException entityExists = new EntityExistsException("foo"); assertSame(DataIntegrityViolationException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityExists).getClass()); TransactionRequiredException transactionRequired = new TransactionRequiredException("foo"); assertSame(InvalidDataAccessApiUsageException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(transactionRequired).getClass()); PersistenceException unknown = new PersistenceException() { }; assertSame(JpaSystemException.class, EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unknown).getClass()); }
private static net.sf.hibernate.NonUniqueObjectException adaptNonUniqueObjectException( final javax.persistence.EntityExistsException ex) { final String message = ex.getMessage(); return new net.sf.hibernate.NonUniqueObjectException(ex.getMessage(), null, null) { @Override public String getMessage() { return message; } @Override public String toString() { return toStringWithClassName(this, net.sf.hibernate.cache.CacheException.class); } }; }
public void printStackTrace(PrintStream out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
public void printStackTrace(PrintWriter out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
final EntityExistsException converted = new EntityExistsException( cause.getMessage() ); handlePersistenceException( converted ); return converted;
public void printStackTrace(PrintStream out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
@Override public Exception translate(Throwable e) { if (e.getCause() != null && isRelevantCause(e.getCause())) { return translate(e.getCause()); } Class<? extends Throwable> c = e.getClass(); if (c.equals(org.apache.openjpa.persistence.EntityExistsException.class)) { return new javax.persistence.EntityExistsException(e.getMessage(), e); } else if (c.equals(javax.validation.ConstraintViolationException.class)) { return (Exception) e; } LOG.info("Cannot translate '{}' to specific subtype, will return generic PersistenceException", e.getClass().getName()); return new PersistenceException(e); }
public void printStackTrace(PrintWriter out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
} catch (final SQLException e) { if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) { throw new EntityExistsException("Entity already exists: ", e); } else { throw new CloudRuntimeException("DB Exception on: " + pstmt, e);
public void printStackTrace(PrintStream out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
} catch (final SQLException e) { if (e.getSQLState().equals("23000") && e.getErrorCode() == 1062) { throw new EntityExistsException("Entity already exists ", e);
public void printStackTrace(PrintWriter out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
if(student.getKey() != null){ if (containsStudent(student)) { throw new EntityExistsException("Object already exists"); } } mgr.makePersistent(student);
public void printStackTrace(PrintWriter out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
@Override public RuntimeException mapManagedFlushFailure(String message, RuntimeException failure, SessionImplementor session) { // OGM-specific if ( EntityAlreadyExistsException.class.isInstance( failure ) ) { throw new EntityExistsException( failure ); } // Let ORM deal with the others else { return delegate.mapManagedFlushFailure( message, failure, session ); } } }
public void printStackTrace(PrintStream out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
break; catch (EntityExistsException e) {throw new EntityExistsException();} catch (PersistenceException e) {} catch (UnexpectedRollbackException e) {}
public void printStackTrace(PrintWriter out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }
@Override @Transactional( propagation = Propagation.REQUIRED, readOnly = false) @CachePut( value = "greetings", key = "#result.id") public Greeting create(Greeting greeting) { logger.info("> create"); counterService.increment("method.invoked.greetingServiceBean.create"); // Ensure the entity object to be created does NOT exist in the // repository. Prevent the default behavior of save() which will update // an existing entity if the entity matching the supplied id exists. if (greeting.getId() != null) { // Cannot create Greeting with specified ID value logger.error( "Attempted to create a Greeting, but id attribute was not null."); throw new EntityExistsException( "The id attribute must be null to persist a new entity."); } Greeting savedGreeting = greetingRepository.save(greeting); logger.info("< create"); return savedGreeting; }
public void printStackTrace(PrintStream out) { super.printStackTrace(out); Exceptions.printNestedThrowables(this, out); }