From f108c4af9271e27c3166db87df69949efd9cbf20 Mon Sep 17 00:00:00 2001 From: Emmanuel Bernard Date: Fri, 25 Sep 2009 11:14:51 +0000 Subject: [PATCH] HHH-4463 do not alter setMaxResult for native queries in getSingleResult() as the query transformation will likely fail. git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17543 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java b/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java index c09552bb07..82dfaee354 100755 --- a/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java +++ b/entitymanager/src/main/java/org/hibernate/ejb/QueryImpl.java @@ -51,6 +51,7 @@ import org.hibernate.HibernateException; import org.hibernate.QueryParameterException; import org.hibernate.TypeMismatchException; +import org.hibernate.SQLQuery; import org.hibernate.engine.query.NamedParameterDescriptor; import org.hibernate.engine.query.OrdinalParameterDescriptor; import org.hibernate.hql.QueryExecutionRequestException; @@ -230,7 +231,9 @@ public X getSingleResult() { 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 - if ( getSpecifiedMaxResults() != 1 ) { + // 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 }