Package javax.persistence

Examples of javax.persistence.PersistenceException


  private <X> void updateInBackend(Key<X, ?> key, X entity) {
    ErraiEntityType<X> entityType = getMetamodel().entity(getNarrowedClass(entity));
    if (backend.isModified(key, entity)) {
      Object currentId = entityType.getId(Object.class).get(entity);
      if (!key.getId().equals(currentId)) {
        throw new PersistenceException(
                "Detected ID attribute change in managed entity. Expected ID: " +
                key.getId() + "; Actual ID: " + currentId);
      }
      entityType.deliverPreUpdate(entity);
      backend.put(key, entity);
View Full Code Here


          }
          else if (attr instanceof ErraiPluralAttribute) {
            parsePluralJsonReference(entity, (ErraiPluralAttribute<? super X, ?, ?>) attr, attrJsonValue.isArray(), eem);
          }
          else {
            throw new PersistenceException("Unknown attribute type " + attr);
          }
        }
      }
      return entity;
    } finally {
View Full Code Here

        }
        else if (attr instanceof ErraiPluralAttribute) {
          attributeValue = makeJsonReference(targetEntity, (ErraiPluralAttribute<? super X, ?, ?>) attr, eem);
        }
        else {
          throw new PersistenceException("Unknown attribute type " + attr);
        }
        jsonValue.put(attr.getName(), attributeValue);
      }
    }
View Full Code Here

    } 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);
  }
View Full Code Here

        ServiceReference[] refs = null;       
        try {
            filter = "(osgi.unit.name="+ unitName +")";
            refs = ctx.getServiceReferences(EntityManagerFactory.class.getName(), filter);
        } catch (InvalidSyntaxException isEx) {
            new PersistenceException("Implementation error - incorrect filter specified while looking up EMF", isEx);
        }
        if ((refs != null) && (refs.length != 0)) {
            debug("Persistence class - lookupEMF, found service ", unitName, " in registry");
            // Take the first one
            return (EntityManagerFactory)ctx.getService(refs[0]);
View Full Code Here

        ServiceReference[] refs = null;       
        try {
            filter = "(osgi.unit.name="+ unitName +")";
            refs = ctx.getServiceReferences(EntityManagerFactoryBuilder.class.getName(), filter);
        } catch (InvalidSyntaxException isEx) {
            new PersistenceException("Implementation error - incorrect filter specified while looking up EMF", isEx);
        }
        if ((refs != null) && (refs.length != 0)) {
            debug("Persistence class - lookupEMFBuilder, found service ", unitName, " in registry");
            // Take the first one and create an EMF from it
            EntityManagerFactoryBuilder builder = (EntityManagerFactoryBuilder)ctx.getService(refs[0]);
View Full Code Here

  //TODO mutualize this code with the EM this will fix the rollback issues

  @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
  private void throwPersistenceException(Exception e) {
    if ( e instanceof StaleStateException ) {
      PersistenceException pe = wrapStaleStateException( ( StaleStateException ) e );
      throwPersistenceException( pe );
    }
    else if ( e instanceof org.hibernate.OptimisticLockException ) {
      PersistenceException converted = wrapLockException( (HibernateException) e, null );
      throwPersistenceException( converted );
    }
    else if ( e instanceof org.hibernate.PessimisticLockException ) {
      PersistenceException converted = wrapLockException( (HibernateException) e, null );
      throwPersistenceException( converted );
    }
    else if ( e instanceof ConstraintViolationException ) {
      //FIXME this is bad cause ConstraintViolationException happens in other circumstances
      throwPersistenceException( new EntityExistsException( e ) );
    }
    else if ( e instanceof org.hibernate.QueryTimeoutException ) {
      javax.persistence.QueryTimeoutException converted = new javax.persistence.QueryTimeoutException(e.getMessage(), e);
      throwPersistenceException( converted );
    }
    else if ( e instanceof ObjectNotFoundException ) {
      throwPersistenceException( new EntityNotFoundException( e.getMessage() ) );
    }
    else if ( e instanceof org.hibernate.NonUniqueResultException ) {
      throwPersistenceException( new NonUniqueResultException( e.getMessage() ) );
    }
    else if ( e instanceof UnresolvableObjectException ) {
      throwPersistenceException( new EntityNotFoundException( e.getMessage() ) );
    }
    else if ( e instanceof QueryException ) {
      throw new IllegalArgumentException( e );
    }
    else if ( e instanceof TransientObjectException ) {
      //FIXME rollback
      throw new IllegalStateException( e ); //Spec 3.2.3 Synchronization rules
    }
    else {
      throwPersistenceException( new PersistenceException( e ) );
    }
  }
View Full Code Here

      throwPersistenceException( new PersistenceException( e ) );
    }
  }

  public PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions) {
    PersistenceException pe;
    if ( e instanceof org.hibernate.OptimisticLockException ) {
      org.hibernate.OptimisticLockException ole = ( org.hibernate.OptimisticLockException ) e;
      pe = new OptimisticLockException( ole.getMessage(), ole, ole.getEntity() );
    }
    else if ( e instanceof org.hibernate.PessimisticLockException ) {
View Full Code Here

    throw e;
  }

  @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
  PersistenceException wrapStaleStateException(StaleStateException e) {
    PersistenceException pe;
    if ( e instanceof StaleObjectStateException ) {
      StaleObjectStateException sose = ( StaleObjectStateException ) e;
      Serializable identifier = sose.getIdentifier();
      if ( identifier != null ) {
        Object entity = session.load( sose.getEntityName(), identifier );
View Full Code Here

                    holder.result = result;
                    holder.exchange = createExchange(result);
                    answer.add(holder);
                }

                PersistenceException cause = null;
                int messagePolled = 0;
                try {
                    messagePolled = processBatch(CastUtils.cast(answer));
                } catch (Exception e) {
                    if (e instanceof PersistenceException) {
                        cause = (PersistenceException) e;
                    } else {
                        cause = new PersistenceException(e);
                    }
                }

                if (cause != null) {
                    if (!isTransacted()) {
                        LOG.warn("Error processing last message due: {}. Will commit all previous successful processed message, and ignore this last failure.", cause.getMessage(), cause);
                    } else {
                        // rollback all by throwning exception
                        throw cause;
                    }
                }
View Full Code Here

TOP

Related Classes of javax.persistence.PersistenceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.