Example usage for javax.persistence NoResultException getCause

List of usage examples for javax.persistence NoResultException getCause

Introduction

In this page you can find the example usage for javax.persistence NoResultException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:com.haulmont.cuba.core.app.RdbmsStore.java

@SuppressWarnings("unchecked")
protected <E extends Entity> List<E> executeQuery(Query query, boolean singleResult) {
    List<E> list;/*ww  w . j  a  v a 2 s  .  c  om*/
    try {
        if (singleResult) {
            try {
                E result = (E) query.getSingleResult();
                list = new ArrayList<>(1);
                list.add(result);
            } catch (NoResultException e) {
                list = Collections.emptyList();
            }
        } else {
            list = query.getResultList();
        }
    } catch (javax.persistence.PersistenceException e) {
        if (e.getCause() instanceof org.eclipse.persistence.exceptions.QueryException && e.getMessage() != null
                && e.getMessage().contains("Fetch group cannot be set on report query")) {
            throw new DevelopmentException("DataManager cannot execute query for single attributes");
        } else {
            throw e;
        }
    }
    return list;
}