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;
}
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) {
}
}
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) {
}
}
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) {
}
}
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());
}
Aggregations