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

@ -2365,24 +2365,14 @@ public abstract class Dialect implements ConversionContext {
// oddly most database in fact seem to, so true is the default.
return true;
}
/**
* 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
* True if limited, false if not.
* @return int The limit, or zero-or-less to indicate no limit.
*/
public boolean limitsParamListSize() {
return false;
}
/**
* If limitsListSize() is true, define the size threshold.
*
* @return int
* The list size threshold
*/
public int getParamListSizeLimit() {
public int getInExpressionCountLimit() {
return 0;
}
}

View File

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

View File

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

View File

@ -190,20 +190,12 @@ public class SQLServerDialect extends AbstractTransactSQLDialect {
protected SqlTypeDescriptor getSqlTypeDescriptorOverride( int sqlCode ) {
return sqlCode == Types.TINYINT ? SmallIntTypeDescriptor.INSTANCE : super.getSqlTypeDescriptorOverride(sqlCode);
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#limitsParamListSize()
*/
* @see org.hibernate.dialect.Dialect#getInExpressionCountLimit()
*/
@Override
public boolean limitsParamListSize() {
return true;
}
/* (non-Javadoc)
* @see org.hibernate.dialect.Dialect#getParamListSizeLimit()
*/
@Override
public int getParamListSizeLimit() {
public int getInExpressionCountLimit() {
return PARAM_LIST_SIZE_LIMIT;
}
}

View File

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

View File

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

View File

@ -75,7 +75,10 @@ import org.jboss.logging.Logger;
* @author Max Andersen
*/
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_TYPE = new MarkerObject("<unset type>");
@ -803,20 +806,13 @@ public abstract class AbstractQueryImpl implements Query {
Collection vals = (Collection) typedList.getValue();
// HHH-1123
// Some DBs limit the size of param lists. For now, warn...
//
// TODO: HHH-1123 was rejected, but this issue may still deserve some
// research.
Dialect dialect = session.getFactory().getDialect();
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.");
// Some DBs limit number of IN expressions. For now, warn...
final Dialect dialect = session.getFactory().getDialect();
final int inExprLimit = dialect.getInExpressionCountLimit();
if ( inExprLimit > 0 && vals.size() > inExprLimit ) {
log.tooManyInExpressions( dialect.getClass().getName(), inExprLimit, name, vals.size() );
}
Type type = typedList.getType();
boolean isJpaPositionalParam = parameterMetadata.getNamedParameterDescriptor( name ).isJpaStyle();

View File

@ -1574,4 +1574,13 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = INFO)
@Message(value = "NaturalId queries executed to database: %s", id = 442)
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
*
* 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
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.