Package javax.persistence

Examples of javax.persistence.TransactionRequiredException


  @Override
    @SuppressWarnings({ "unchecked" })
  public TypedQuery<X> setLockMode(javax.persistence.LockModeType lockModeType) {
    if (! getEntityManager().isTransactionInProgress()) {
      throw new TransactionRequiredException( "no transaction is in progress" );
    }
    if ( ! canApplyLockModes() ) {
      throw new IllegalStateException( "Not a JPAQL/Criteria query" );
    }
    this.jpaLockMode = lockModeType;
View Full Code Here


   */
  @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
  public int executeUpdate() {
    try {
      if ( ! entityManager.isTransactionInProgress() ) {
        entityManager.throwPersistenceException( new TransactionRequiredException( "Executing an update/delete query" ) );
        return 0;
      }
      return internalExecuteUpdate();
    }
    catch ( QueryExecutionRequestException he) {
View Full Code Here

  }

  @Override
  public int executeUpdate() {
    if ( ! entityManager().isTransactionInProgress() ) {
      throw new TransactionRequiredException( "javax.persistence.Query.executeUpdate requires active transaction" );
    }

    // the expectation is that there is just one Output, of type UpdateCountOutput
    try {
      execute();
View Full Code Here

    //As a result, it is only the outer map that needs to be thread safe.
   
    //Throw the error on to the client
    if(!!!isTransactionActive()) {
      if(jtaIntegrationAvailable())
        throw new TransactionRequiredException("No transaction currently active");
      else {
        throw new TransactionRequiredException("No JTA transaction services implementation is currently available. As a result the" +
            " JPA container cannot integrate with JTA transactions.");
      }
    }
    EntityManager toReturn = null;
   
    //Get hold of the Map. If there is no Map already registered then add one.
    //We don't need to worry about a race condition, as no other thread will
    //share our transaction and be able to access our Map
    Map<EntityManagerFactory, EntityManager> contextsForTransaction = (Map<EntityManagerFactory, EntityManager>) tranRegistry.getResource(EMF_MAP_KEY);
   
    //If we have a map then find an EntityManager, else create a new Map add it to the registry, and register for cleanup
    if(contextsForTransaction != null) {
      toReturn = contextsForTransaction.get(persistenceUnit);
    } else {
      contextsForTransaction = new IdentityHashMap<EntityManagerFactory, EntityManager>();
      try {
        tranRegistry.putResource(EMF_MAP_KEY, contextsForTransaction);
      } catch (IllegalStateException e) {
        _logger.warn("Unable to create a persistence context for the transaction {} because the is not active", new Object[] {tranRegistry.getTransactionKey()});
        throw new TransactionRequiredException("Unable to assiociate resources with transaction " + tranRegistry.getTransactionKey());
      }
    }
   
    //If we have no previously created EntityManager
    if(toReturn == null) {
      toReturn = (properties == null) ? persistenceUnit.createEntityManager() : persistenceUnit.createEntityManager(properties);
      if(_logger.isDebugEnabled())
        _logger.debug("Created a new persistence context {} for transaction {}.", new Object[] {toReturn, tranRegistry.getTransactionKey()});
      try {
        tranRegistry.registerInterposedSynchronization(new EntityManagerClearUp(toReturn));
      } catch (IllegalStateException e) {
        _logger.warn("No persistence context could be created as the JPA container could not register a synchronization with the transaction {}.", new Object[] {tranRegistry.getTransactionKey()});
        toReturn.close();
        throw new TransactionRequiredException("Unable to synchronize with transaction " + tranRegistry.getTransactionKey());
      }
      contextsForTransaction.put(persistenceUnit, toReturn);
    } else {
      if(_logger.isDebugEnabled())
        _logger.debug("Re-using a persistence context for transaction " + tranRegistry.getTransactionKey());
View Full Code Here

    }

    private EntityManager getEntityManager(boolean activeRequired) {
        TransactionImpl transaction = (TransactionImpl) transactionManager.getTransaction();
        if (activeRequired && (transaction == null || transaction.getStatus() != Status.STATUS_ACTIVE)) {
            throw new TransactionRequiredException("No active transaction");
        }
        if (transaction == null) {
            return null;
        }
        EntityManagerWrapper entityManagerWrapper = (EntityManagerWrapper) transactionManager.getResource(persistenceUnit);
        if (entityManagerWrapper == null) {
            EntityManager entityManager = createEntityManager();
            entityManagerWrapper = new EntityManagerWrapperTxScoped(entityManager);
            transactionManager.putResource(persistenceUnit, entityManagerWrapper);
            try {
                transaction.registerSynchronization(entityManagerWrapper);
            } catch (javax.transaction.RollbackException e) {
                throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e);
            } catch (SystemException e) {
                throw (TransactionRequiredException) new TransactionRequiredException("No active transaction").initCause(e);
            }
        }
        return entityManagerWrapper.getEntityManager();
    }
View Full Code Here

  }

  private void checkTransactionNeeded() {
    if ( persistenceContextType == PersistenceContextType.TRANSACTION && ! isTransactionInProgress() ) {
      //no need to mark as rollback, no tx in progress
      throw new TransactionRequiredException(
          "no transaction is in progress for a TRANSACTION type persistence context"
      );
    }
  }
View Full Code Here

  }

  public void flush() {
    try {
      if ( ! isTransactionInProgress() ) {
        throw new TransactionRequiredException( "no transaction is in progress" );
      }
      //adjustFlushMode();
      getSession().flush();
    }
    catch (HibernateException he) {
View Full Code Here

  }

  public void lock(Object entity, LockModeType lockMode) {
    try {
      if ( ! isTransactionInProgress() ) {
        throw new TransactionRequiredException( "no transaction is in progress" );
      }
      //adjustFlushMode();
      if ( !contains( entity ) ) throw new IllegalArgumentException( "entity not in the persistence context" );
      getSession().lock( entity, getLockMode( lockMode ) );
    }
View Full Code Here

            if ( ignoreNotJoining ) {
              log.debug( "No JTA transaction found" );
              return;
            }
            else {
              throw new TransactionRequiredException(
                  "No active JTA transaction on joinTransaction call"
              );
            }
          }
          else
View Full Code Here

    protected void throwUserTransactionException() {
        throw TransactionException.entityTransactionWithJTANotAllowed();
    }

    protected void throwCheckTransactionFailedException() {
        throw new TransactionRequiredException(TransactionException.externalTransactionNotActive().getMessage());
    }
View Full Code Here

TOP

Related Classes of javax.persistence.TransactionRequiredException

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.