Author: epbernard
Date: 2008-08-15 11:55:04 -0400 (Fri, 15 Aug 2008)
New Revision: 15089
Modified:
entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java
Log:
EJB-375 fix faulty algo
Modified: entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
--- entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java 2008-08-15 10:02:32 UTC
(rev 15088)
+++ entitymanager/trunk/src/java/org/hibernate/ejb/QueryImpl.java 2008-08-15 15:55:04 UTC
(rev 15089)
@@ -19,6 +19,7 @@
import org.hibernate.HibernateException;
import org.hibernate.QueryParameterException;
import org.hibernate.TypeMismatchException;
+import org.hibernate.impl.AbstractQueryImpl;
import org.hibernate.ejb.util.ConfigurationHelper;
import org.hibernate.hql.QueryExecutionRequestException;
@@ -79,9 +80,26 @@
public Object getSingleResult() {
try {
- if (maxResults != 1) query.setMaxResults( 2 ); //avoid OOME if the list is huge
- List result = query.list();
- if ( maxResults != -1 ) query.setMaxResults( maxResults ); //put back the original
value
+ List result;
+ /* Avoid OOME if the list() is huge (user faulty query) by limiting the query to 2
elements max */
+ //FIXME: get rid of this impl binding (HHH-3432)
+ if ( query instanceof AbstractQueryImpl ) {
+ if (maxResults != 1) query.setMaxResults( 2 ); //avoid OOME if the list is huge
+ result = query.list();
+ if ( maxResults != -1 ) {
+ query.setMaxResults( maxResults ); //put back the original value
+ }
+ else {
+ AbstractQueryImpl queryImpl = AbstractQueryImpl.class.cast( query );
+ queryImpl.getSelection().setMaxRows( null );
+ }
+ }
+ else {
+ //we can't do much because we cannot reset the maxResults => do the full list
call
+ //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" ) );
}
Show replies by date