Example usage for javax.persistence NonUniqueResultException NonUniqueResultException

List of usage examples for javax.persistence NonUniqueResultException NonUniqueResultException

Introduction

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

Prototype

public NonUniqueResultException() 

Source Link

Document

Constructs a new NonUniqueResultException exception with null as its detail message.

Usage

From source file:org.jnap.core.persistence.jpa.DaoSupport.java

/**
 * /*  w w w. j  a  v a2 s . c  o  m*/
 * @param result
 * @return
 * @throws QueryException
 */
protected E handleUniqueResult(List<E> result) throws PersistenceException {
    E uniqueResult = null;
    if (result != null && result.size() > 0) {
        if (result.size() == 1) {
            uniqueResult = result.get(0);
        } else {
            throw new NonUniqueResultException(); //TODO
        }
    }
    return uniqueResult;
}

From source file:org.batoo.jpa.core.impl.criteria.QueryImpl.java

/**
 * {@inheritDoc}//from  w  w  w.j  ava2s  . c om
 * 
 */
@Override
public X getSingleResult() {
    final List<X> resultList = this.getResultList();

    if (resultList.size() > 1) {
        throw new NonUniqueResultException();
    }

    if (resultList.size() == 0) {
        throw new NoResultException();
    }

    return resultList.get(0);
}

From source file:org.batoo.jpa.core.impl.nativeQuery.NativeQuery.java

/**
 * {@inheritDoc}// ww  w .  j  a  v  a  2  s .c  o  m
 * 
 */
@Override
public Object getSingleResult() {
    final List<?> resultList = this.getResultList();

    if (resultList.size() > 1) {
        throw new NonUniqueResultException();
    }

    if (resultList.size() == 0) {
        throw new NoResultException();
    }

    return resultList.get(0);
}