Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

HHH-7233 - unmuck EntityManager#getSingleResult wrt auto-setting of m…

…ax results
  • Loading branch information...
commit 4785d7eb2e63f6d692908e84e29f64fa62b9a1a1 1 parent 14d1c62
@sebersole sebersole authored
View
17 hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/QueryImpl.java
@@ -277,19 +277,7 @@ protected void applyAliasSpecificLockMode(String alias, LockMode lockMode) {
@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<X> result = query.list();
- if ( mucked ) {
- query.setMaxResults( getSpecifiedMaxResults() );
- }
+ final List<X> result = query.list();
if ( result.size() == 0 ) {
NoResultException nre = new NoResultException( "No entity found for query" );
@@ -297,7 +285,7 @@ public X getSingleResult() {
throw nre;
}
else if ( result.size() > 1 ) {
- Set<X> uniqueResult = new HashSet<X>(result);
+ final Set<X> uniqueResult = new HashSet<X>(result);
if ( uniqueResult.size() > 1 ) {
NonUniqueResultException nure = new NonUniqueResultException( "result returns more than one elements" );
getEntityManager().handlePersistenceException( nure );
@@ -306,7 +294,6 @@ else if ( result.size() > 1 ) {
else {
return uniqueResult.iterator().next();
}
-
}
else {
return result.get( 0 );
Please sign in to comment.
Something went wrong with that request. Please try again.