Search in sources :

Example 91 with NoResultException

use of javax.persistence.NoResultException in project hibernate-orm by hibernate.

the class AuditReaderImpl method find.

@Override
@SuppressWarnings({ "unchecked" })
public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision, boolean includeDeletions) throws IllegalArgumentException, NotAuditedException, IllegalStateException {
    cls = getTargetClassIfProxied(cls);
    checkNotNull(cls, "Entity class");
    checkNotNull(entityName, "Entity name");
    checkNotNull(primaryKey, "Primary key");
    checkNotNull(revision, "Entity revision");
    checkPositive(revision, "Entity revision");
    checkSession();
    if (firstLevelCache.contains(entityName, revision, primaryKey)) {
        return (T) firstLevelCache.get(entityName, revision, primaryKey);
    }
    Object result;
    try {
        // The result is put into the cache by the entity instantiator called from the query
        result = createQuery().forEntitiesAtRevision(cls, entityName, revision, includeDeletions).add(AuditEntity.id().eq(primaryKey)).getSingleResult();
    } catch (NoResultException e) {
        result = null;
    } catch (NonUniqueResultException e) {
        throw new AuditException(e);
    }
    return (T) result;
}
Also used : NonUniqueResultException(org.hibernate.NonUniqueResultException) AuditException(org.hibernate.envers.exception.AuditException) NoResultException(javax.persistence.NoResultException)

Example 92 with NoResultException

use of javax.persistence.NoResultException in project guice by google.

the class JoiningLocalTransactionsTest method testSimpleTransactionRollbackOnUnchecked.

public void testSimpleTransactionRollbackOnUnchecked() {
    try {
        injector.getInstance(JoiningLocalTransactionsTest.TransactionalObject.class).runOperationInTxnThrowingUnchecked();
    } catch (RuntimeException re) {
        //ignore
        injector.getInstance(UnitOfWork.class).end();
    }
    EntityManager em = injector.getInstance(EntityManager.class);
    assertFalse("Session was not closed by transactional service (rollback didnt happen?)", em.getTransaction().isActive());
    try {
        Object result = em.createQuery("from JpaTestEntity where text = :text").setParameter("text", TRANSIENT_UNIQUE_TEXT).getSingleResult();
        injector.getInstance(UnitOfWork.class).end();
        fail("a result was returned! rollback sure didnt happen!!!");
    } catch (NoResultException e) {
    }
}
Also used : UnitOfWork(com.google.inject.persist.UnitOfWork) EntityManager(javax.persistence.EntityManager) NoResultException(javax.persistence.NoResultException)

Example 93 with NoResultException

use of javax.persistence.NoResultException in project guice by google.

the class ManagedLocalTransactionsTest method testSimpleTransactionRollbackOnChecked.

public void testSimpleTransactionRollbackOnChecked() {
    try {
        injector.getInstance(TransactionalObject.class).runOperationInTxnThrowingChecked();
    } catch (IOException e) {
        //ignore
        injector.getInstance(UnitOfWork.class).end();
    }
    EntityManager em = injector.getInstance(EntityManager.class);
    assertFalse("Previous EM was not closed by transactional service (rollback didnt happen?)", em.getTransaction().isActive());
    //test that the data has been stored
    try {
        Object result = em.createQuery("from JpaTestEntity where text = :text").setParameter("text", TRANSIENT_UNIQUE_TEXT).getSingleResult();
        injector.getInstance(UnitOfWork.class).end();
        fail("a result was returned! rollback sure didnt happen!!!");
    } catch (NoResultException e) {
    }
}
Also used : UnitOfWork(com.google.inject.persist.UnitOfWork) EntityManager(javax.persistence.EntityManager) IOException(java.io.IOException) NoResultException(javax.persistence.NoResultException)

Example 94 with NoResultException

use of javax.persistence.NoResultException in project guice by google.

the class ManagedLocalTransactionsTest method testSimpleTransactionRollbackOnUnchecked.

public void testSimpleTransactionRollbackOnUnchecked() {
    try {
        injector.getInstance(TransactionalObject.class).runOperationInTxnThrowingUnchecked();
    } catch (RuntimeException re) {
        //ignore
        injector.getInstance(UnitOfWork.class).end();
    }
    EntityManager em = injector.getInstance(EntityManager.class);
    assertFalse("Session was not closed by transactional service (rollback didnt happen?)", em.getTransaction().isActive());
    try {
        Object result = em.createQuery("from JpaTestEntity where text = :text").setParameter("text", TRANSIENT_UNIQUE_TEXT).getSingleResult();
        injector.getInstance(UnitOfWork.class).end();
        fail("a result was returned! rollback sure didnt happen!!!");
    } catch (NoResultException e) {
    }
}
Also used : UnitOfWork(com.google.inject.persist.UnitOfWork) EntityManager(javax.persistence.EntityManager) NoResultException(javax.persistence.NoResultException)

Example 95 with NoResultException

use of javax.persistence.NoResultException in project google-app-engine-jappstart by taylorleese.

the class PersistentTokenRepositoryImpl method getTokenForSeries.

/**
     * Gets the token for the given series.
     *
     * @param series the series
     * @return the remember me token
     */
@Override
public final PersistentRememberMeToken getTokenForSeries(final String series) {
    PersistentLogin persistentLogin = null;
    final Query query = entityManager.createQuery("SELECT p FROM PersistentLogin p WHERE series = :series");
    query.setParameter("series", series);
    try {
        persistentLogin = (PersistentLogin) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
    return new PersistentRememberMeToken(persistentLogin.getUsername(), persistentLogin.getSeries(), persistentLogin.getToken(), persistentLogin.getLastUsed());
}
Also used : PersistentRememberMeToken(org.springframework.security.web.authentication.rememberme.PersistentRememberMeToken) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) PersistentLogin(com.jappstart.model.auth.PersistentLogin)

Aggregations

NoResultException (javax.persistence.NoResultException)169 Query (javax.persistence.Query)130 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)14 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4