HHH-8432 - Expanding parameters in IN clause

This commit is contained in:
Lukasz Antoniak 2013-08-24 19:49:03 +02:00 committed by Brett Meyer
parent 0f1e971e62
commit 9e3e86388b
2 changed files with 47 additions and 2 deletions

View File

@ -802,8 +802,12 @@ public abstract class AbstractQueryImpl implements Query {
Iterator iter = vals.iterator();
int i = 0;
while ( iter.hasNext() ) {
String alias = ( isJpaPositionalParam ? 'x' + name : name ) + i++ + '_';
namedParamsCopy.put( alias, new TypedValue( type, iter.next() ) );
// Variable 'name' can represent a number or contain digit at the end. Surrounding it with
// characters to avoid ambiguous definition after concatenating value of 'i' counter.
String alias = ( isJpaPositionalParam ? 'x' + name : name ) + '_' + i++ + '_';
if ( namedParamsCopy.put( alias, new TypedValue( type, iter.next() ) ) != null ) {
throw new HibernateException( "Repeated usage of alias '" + alias + "' while expanding list parameter." );
}
list.append( ParserHelper.HQL_VARIABLE_PREFIX ).append( alias );
if ( iter.hasNext() ) {
list.append( ", " );

View File

@ -162,6 +162,47 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
s.close();
}
@Test
@TestForIssue( jiraKey = "HHH-8432" )
public void testExpandListParameter() {
final Object[] namesArray = new Object[] {
"ZOO 1", "ZOO 2", "ZOO 3", "ZOO 4", "ZOO 5", "ZOO 6", "ZOO 7",
"ZOO 8", "ZOO 9", "ZOO 10", "ZOO 11", "ZOO 12"
};
final Object[] citiesArray = new Object[] {
"City 1", "City 2", "City 3", "City 4", "City 5", "City 6", "City 7",
"City 8", "City 9", "City 10", "City 11", "City 12"
};
Session session = openSession();
session.getTransaction().begin();
Address address = new Address();
Zoo zoo = new Zoo( "ZOO 1", address );
address.setCity( "City 1" );
session.save( zoo );
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
List result = session.createQuery( "FROM Zoo z WHERE z.name IN (?1) and z.address.city IN (?11)" )
.setParameterList( "1", namesArray )
.setParameterList( "11", citiesArray )
.list();
assertEquals( 1, result.size() );
session.getTransaction().commit();
session.clear();
session.getTransaction().begin();
zoo = (Zoo) session.get( Zoo.class, zoo.getId() );
session.delete( zoo );
session.getTransaction().commit();
session.close();
}
@Test
public void testJpaTypeOperator() {
// just checking syntax here...