diff --git a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java index 2b053dfa2e..80deff020e 100755 --- a/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java +++ b/hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java @@ -277,19 +277,7 @@ public class QueryImpl extends AbstractQueryImpl implements TypedQuery, @SuppressWarnings({ "unchecked", "RedundantCast" }) public X getSingleResult() { try { - boolean mucked = false; - // IMPL NOTE : the mucking with max results here is attempting to help the user from shooting themselves - // in the foot in the case where they have a large query by limiting the query results to 2 max - // SQLQuery cannot be safely paginated, leaving the user's choice here. - if ( getSpecifiedMaxResults() != 1 && - ! ( SQLQuery.class.isAssignableFrom( query.getClass() ) ) ) { - mucked = true; - query.setMaxResults( 2 ); //avoid OOME if the list is huge - } - List result = query.list(); - if ( mucked ) { - query.setMaxResults( getSpecifiedMaxResults() ); - } + final List result = query.list(); if ( result.size() == 0 ) { NoResultException nre = new NoResultException( "No entity found for query" ); @@ -297,7 +285,7 @@ public class QueryImpl extends AbstractQueryImpl implements TypedQuery, throw nre; } else if ( result.size() > 1 ) { - Set uniqueResult = new HashSet(result); + final Set uniqueResult = new HashSet(result); if ( uniqueResult.size() > 1 ) { NonUniqueResultException nure = new NonUniqueResultException( "result returns more than one elements" ); getEntityManager().handlePersistenceException( nure ); @@ -306,7 +294,6 @@ public class QueryImpl extends AbstractQueryImpl implements TypedQuery, else { return uniqueResult.iterator().next(); } - } else { return result.get( 0 );