Package javax.persistence

Examples of javax.persistence.NoResultException


      Object value = null;

      if (rs.next())
        value = rs.getObject(1);
      else // jpa/1004
        throw new NoResultException("Query returned no results for getSingleResult()");

      // jpa/1005
      if (rs.next())
        throw new NonUniqueResultException("Query returned more than one result for getSingleResult()");
View Full Code Here


  @SuppressWarnings({ "ThrowableInstanceNeverThrown" })
  public Object getSingleResult() {
    try {
      List result = query.list();
      if ( result.size() == 0 ) {
        throwPersistenceException( new NoResultException( "No entity found for query" ) );
      }
      else if ( result.size() > 1 ) {
        Set uniqueResult = new HashSet( result );
        if ( uniqueResult.size() > 1 ) {
          throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements" ) );
View Full Code Here

    public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException {
        List result = list();

        if (result == null || result.size() == 0) {
            throw new NoResultException();
        }

        if (result.size() > 1) {
            throw new NonUniqueResultException();
        }
View Full Code Here

  @Override
  public X getSingleResult() {
    List<X> resultList = getResultList();
    if (resultList.isEmpty()) {
      throw new NoResultException();
    } else if (resultList.size() > 1) {
      throw new NonUniqueResultException("Query produced " + resultList.size() + " results (expected 1)");
    }
    return resultList.get(0);
  }
View Full Code Here

    getEntityManager().checkOpen( true );
    try {
      final List<X> result = query.list();

      if ( result.size() == 0 ) {
        NoResultException nre = new NoResultException( "No entity found for query" );
        getEntityManager().handlePersistenceException( nre );
        throw nre;
      }
      else if ( result.size() > 1 ) {
        final Set<X> uniqueResult = new HashSet<X>(result);
View Full Code Here

      if ( mucked ) {
        query.setMaxResults( getSpecifiedMaxResults() );
      }

      if ( result.size() == 0 ) {
        NoResultException nre = new NoResultException( "No entity found for query" );
        getEntityManager().handlePersistenceException( nre );
        throw nre;
      }
      else if ( result.size() > 1 ) {
        Set<X> uniqueResult = new HashSet<X>(result);
View Full Code Here

      if ( mucked ) {
        query.setMaxResults( getSpecifiedMaxResults() );
      }

      if ( result.size() == 0 ) {
        NoResultException nre = new NoResultException( "No entity found for query" );
        getEntityManager().handlePersistenceException( nre );
        throw nre;
      }
      else if ( result.size() > 1 ) {
        Set<X> uniqueResult = new HashSet<X>(result);
View Full Code Here

        //Not tremendously bad as the user is doing a fault here anyway by calling getSingleREsults on a big list
        result = query.list();
      }

      if ( result.size() == 0 ) {
        em.throwPersistenceException( new NoResultException( "No entity found for query" ) );
      }
      else if ( result.size() > 1 ) {
        Set uniqueResult = new HashSet(result);
        if ( uniqueResult.size() > 1 ) {
          em.throwPersistenceException( new NonUniqueResultException( "result returns more than one elements") );
View Full Code Here

      if ( mucked ) {
        query.setMaxResults( getSpecifiedMaxResults() );
      }

      if ( result.size() == 0 ) {
        NoResultException nre = new NoResultException( "No entity found for query" );
        getEntityManager().handlePersistenceException( nre );
        throw nre;
      }
      else if ( result.size() > 1 ) {
        Set<X> uniqueResult = new HashSet<X>(result);
View Full Code Here

    public Object getSingleResult() throws AuditException, NonUniqueResultException, NoResultException {
        List result = list();

        if (result == null || result.size() == 0) {
            throw new NoResultException();
        }

        if (result.size() > 1) {
            throw new NonUniqueResultException();
        }
View Full Code Here

TOP

Related Classes of javax.persistence.NoResultException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.