HHH-1123 - Cannot put more than 1000 elements in a InExpression

This commit is contained in:
Steve Ebersole 2012-09-05 11:28:13 -05:00
parent 970bd8679e
commit 40574b9d8a
9 changed files with 45 additions and 90 deletions

View File

@ -2367,22 +2367,12 @@ public abstract class Dialect implements ConversionContext {
} }
/** /**
* Does this databases restrict the number of parameters in a query list? * Return the limit that the underlying database places on the number elements in an {@code IN} predicate.
* If the database defines no such limits, simply return zero or less-than-zero.
* *
* @return boolean * @return int The limit, or zero-or-less to indicate no limit.
* True if limited, false if not.
*/ */
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return false;
}
/**
* If limitsListSize() is true, define the size threshold.
*
* @return int
* The list size threshold
*/
public int getParamListSizeLimit() {
return 0; return 0;
} }
} }

View File

@ -564,18 +564,10 @@ public class Oracle8iDialect extends Dialect {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize() * @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/ */
@Override @Override
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
return PARAM_LIST_SIZE_LIMIT; return PARAM_LIST_SIZE_LIMIT;
} }

View File

@ -371,18 +371,10 @@ public class Oracle9Dialect extends Dialect {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize() * @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/ */
@Override @Override
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
return PARAM_LIST_SIZE_LIMIT; return PARAM_LIST_SIZE_LIMIT;
} }
} }

View File

@ -192,18 +192,10 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize() * @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/ */
@Override @Override
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
return PARAM_LIST_SIZE_LIMIT; return PARAM_LIST_SIZE_LIMIT;
} }
} }

View File

@ -34,18 +34,10 @@ public class SybaseDialect extends AbstractTransactSQLDialect {
private static final int PARAM_LIST_SIZE_LIMIT = 250000; private static final int PARAM_LIST_SIZE_LIMIT = 250000;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize() * @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/ */
@Override @Override
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
return PARAM_LIST_SIZE_LIMIT; return PARAM_LIST_SIZE_LIMIT;
} }
} }

View File

@ -260,18 +260,10 @@ public class TeradataDialect extends Dialect {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize() * @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/ */
@Override @Override
public boolean limitsParamListSize() { public int getInExpressionCountLimit() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
return PARAM_LIST_SIZE_LIMIT; return PARAM_LIST_SIZE_LIMIT;
} }
} }

View File

@ -75,7 +75,10 @@ import org.jboss.logging.Logger;
* @author Max Andersen * @author Max Andersen
*/ */
public abstract class AbstractQueryImpl implements Query { public abstract class AbstractQueryImpl implements Query {
private static final Logger log = Logger.getLogger( AbstractQueryImpl.class ); private static final CoreMessageLogger log = Logger.getMessageLogger(
CoreMessageLogger.class,
AbstractQueryImpl.class.getName()
);
private static final Object UNSET_PARAMETER = new MarkerObject("<unset parameter>"); private static final Object UNSET_PARAMETER = new MarkerObject("<unset parameter>");
private static final Object UNSET_TYPE = new MarkerObject("<unset type>"); private static final Object UNSET_TYPE = new MarkerObject("<unset type>");
@ -803,18 +806,11 @@ public abstract class AbstractQueryImpl implements Query {
Collection vals = (Collection) typedList.getValue(); Collection vals = (Collection) typedList.getValue();
// HHH-1123 // HHH-1123
// Some DBs limit the size of param lists. For now, warn... // Some DBs limit number of IN expressions. For now, warn...
// final Dialect dialect = session.getFactory().getDialect();
// TODO: HHH-1123 was rejected, but this issue may still deserve some final int inExprLimit = dialect.getInExpressionCountLimit();
// research. if ( inExprLimit > 0 && vals.size() > inExprLimit ) {
Dialect dialect = session.getFactory().getDialect(); log.tooManyInExpressions( dialect.getClass().getName(), inExprLimit, name, vals.size() );
if (dialect.limitsParamListSize()
&& vals.size() >= dialect.getParamListSizeLimit()) {
log.warn(dialect.getClass().getName()
+ " limits the size of parameter lists to "
+ dialect.getParamListSizeLimit()
+ " entries. The given list size of "
+ vals.size() + " may cause failures.");
} }
Type type = typedList.getType(); Type type = typedList.getType();

View File

@ -1574,4 +1574,13 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = INFO) @LogMessage(level = INFO)
@Message(value = "NaturalId queries executed to database: %s", id = 442) @Message(value = "NaturalId queries executed to database: %s", id = 442)
void naturalIdQueriesExecuted(long naturalIdQueriesExecutionCount); void naturalIdQueriesExecuted(long naturalIdQueriesExecutionCount);
@LogMessage(level = WARN)
@Message(
value = "Dialect [%s] limits the number of elements in an IN predicate to %s entries. " +
"However, the given parameter list [%s] contained %s entries, which will likely cause failures " +
"to execute the query in the database",
id = 443
)
void tooManyInExpressions(String dialectName, int limit, String paramName, int size);
} }

View File

@ -1,7 +1,7 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2008-2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2012, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.