Fixed HHH-10517: ClassCastException using Restrictions.in with child

classes in Criteria based on parent class.
This commit is contained in:
bdragan 2016-02-25 22:17:29 +01:00 committed by Vlad Mihalcea
parent fe247985f2
commit 54c2586a01
2 changed files with 46 additions and 1 deletions

View File

@ -83,7 +83,7 @@ public class InExpression implements Criterion {
}
else {
for ( Object value : values ) {
list.add( new TypedValue( type, value ) );
list.add( criteriaQuery.getTypedValue( criteria, propertyName, value ) );
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.criteria;
import static org.junit.Assert.assertEquals;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* @author Dragan Bozanovic (draganb)
*/
public class InTest extends BaseCoreFunctionalTestCase {
public String[] getMappings() {
return new String[]{ "criteria/Person.hbm.xml" };
}
@Test
public void testIn() {
Session session = openSession();
Transaction tx = session.beginTransaction();
session.save( new Woman() );
session.save( new Man() );
session.flush();
tx.commit();
session.close();
session = openSession();
tx = session.beginTransaction();
List persons = session.createCriteria( Person.class ).add(
Restrictions.in( "class", Woman.class ) ).list();
assertEquals( 1, persons.size() );
tx.rollback();
session.close();
}
}