Search in sources :

Example 1 with NoResultException

use of javax.persistence.NoResultException in project che by eclipse.

the class JpaWorkspaceDao method get.

@Override
@Transactional
public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException {
    requireNonNull(name, "Required non-null name");
    requireNonNull(namespace, "Required non-null namespace");
    try {
        return new WorkspaceImpl(managerProvider.get().createNamedQuery("Workspace.getByName", WorkspaceImpl.class).setParameter("namespace", namespace).setParameter("name", name).getSingleResult());
    } catch (NoResultException noResEx) {
        throw new NotFoundException(format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace));
    } catch (RuntimeException x) {
        throw new ServerException(x.getLocalizedMessage(), x);
    }
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 2 with NoResultException

use of javax.persistence.NoResultException in project che by eclipse.

the class JpaAccountDao method getByName.

@Override
@Transactional
public AccountImpl getByName(String name) throws ServerException, NotFoundException {
    requireNonNull(name, "Required non-null account name");
    final EntityManager manager = managerProvider.get();
    try {
        return manager.createNamedQuery("Account.getByName", AccountImpl.class).setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        throw new NotFoundException(String.format("Account with name '%s' was not found", name));
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 3 with NoResultException

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

the class AbstractOneToOneMapper method nullSafeMapToEntityFromMap.

@Override
public void nullSafeMapToEntityFromMap(EnversService enversService, Object obj, Map data, Object primaryKey, AuditReaderImplementor versionsReader, Number revision) {
    final EntityInfo referencedEntity = getEntityInfo(enversService, referencedEntityName);
    Object value;
    try {
        value = queryForReferencedEntity(versionsReader, referencedEntity, (Serializable) primaryKey, revision);
    } catch (NoResultException e) {
        value = null;
    } catch (NonUniqueResultException e) {
        throw new AuditException("Many versions results for one-to-one relationship " + entityName + "." + getPropertyData().getBeanName() + ".", e);
    }
    setPropertyValue(obj, value);
}
Also used : NonUniqueResultException(org.hibernate.NonUniqueResultException) Serializable(java.io.Serializable) AuditException(org.hibernate.envers.exception.AuditException) NoResultException(javax.persistence.NoResultException)

Example 4 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblMleJpaController method findTblMleByUUID.

public TblMle findTblMleByUUID(String uuid_hex) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblMle.findByUUID_Hex");
        query.setParameter("uuid_hex", uuid_hex);
        TblMle tblOem = (TblMle) query.getSingleResult();
        return tblOem;
    } catch (NoResultException e) {
        log.error("NoResultException : MLE with UUID {} not found", uuid_hex);
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblMle(com.intel.mtwilson.as.data.TblMle) NoResultException(javax.persistence.NoResultException)

Example 5 with NoResultException

use of javax.persistence.NoResultException in project OpenAttestation by OpenAttestation.

the class TblModuleManifestJpaController method findTblModuleManifestByHardwareUuid.

public List<TblModuleManifest> findTblModuleManifestByHardwareUuid(String uuid) {
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblModuleManifest.findByHardwareUuid");
        query.setParameter("uuid_hex", uuid);
        List<TblModuleManifest> moduleList = query.getResultList();
        return moduleList;
    } catch (NoResultException e) {
        log.error(String.format("Module information with UUID {} not found in the DB.", uuid));
        return null;
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblModuleManifest(com.intel.mtwilson.as.data.TblModuleManifest) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)356 Query (javax.persistence.Query)205 EntityManager (javax.persistence.EntityManager)69 NonUniqueResultException (javax.persistence.NonUniqueResultException)33 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)25 TypedQuery (javax.persistence.TypedQuery)22 Transactional (org.springframework.transaction.annotation.Transactional)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 Test (org.junit.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Session (org.hibernate.Session)13 UnitOfWork (com.google.inject.persist.UnitOfWork)12 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)11 PersistenceException (javax.persistence.PersistenceException)11 Date (java.util.Date)9 NotFoundException (org.opencastproject.util.NotFoundException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 List (java.util.List)8 NamedQuery (javax.persistence.NamedQuery)8