Example usage for javax.persistence NonUniqueResultException initCause

List of usage examples for javax.persistence NonUniqueResultException initCause

Introduction

In this page you can find the example usage for javax.persistence NonUniqueResultException initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:org.sonar.jpa.session.JpaDatabaseSession.java

/**
 * @return the result or <code>null</code>, if not found
 * @throws NonUniqueResultException if more than one result
 *///from  w  ww.j av a  2s .co  m
@Override
public <T> T getSingleResult(Class<T> entityClass, Object... criterias) {
    try {
        return getSingleResult(getQueryForCriterias(entityClass, true, criterias), (T) null);

    } catch (NonUniqueResultException ex) {
        NonUniqueResultException e = new NonUniqueResultException("Expected single result for entitiy "
                + entityClass.getSimpleName() + " with criterias : " + StringUtils.join(criterias, ","));
        throw (NonUniqueResultException) e.initCause(ex);
    }
}