diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/predicate/InPredicate.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/predicate/InPredicate.java index 30e0a3a9cd..6ac1bc8566 100755 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/predicate/InPredicate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/predicate/InPredicate.java @@ -98,6 +98,7 @@ public class InPredicate * @param expression The expression. * @param values The value list. */ + @SuppressWarnings("unchecked") public InPredicate( CriteriaBuilderImpl criteriaBuilder, Expression expression, @@ -110,9 +111,13 @@ public class InPredicate ? ValueHandlerFactory.determineAppropriateHandler((Class) javaType) : new ValueHandlerFactory.NoOpValueHandler(); for ( T value : values ) { - this.values.add( - new LiteralExpression( criteriaBuilder, valueHandler.convert( value ) ) - ); + if ( value instanceof Expression ) { + this.values.add( (Expression) value ); + } + else { + this.values.add( + new LiteralExpression( criteriaBuilder, valueHandler.convert( value ) ) ); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/InWithHeterogeneousCollectionTest.java b/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/InWithHeterogeneousCollectionTest.java new file mode 100644 index 0000000000..0d76112590 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/query/criteria/internal/InWithHeterogeneousCollectionTest.java @@ -0,0 +1,89 @@ +/* + * 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 . + */ +package org.hibernate.query.criteria.internal; + +import java.util.Arrays; +import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Expression; +import javax.persistence.criteria.Path; +import javax.persistence.criteria.Root; + +import org.hibernate.dialect.H2Dialect; + +import org.hibernate.testing.RequiresDialect; +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Assert; +import org.junit.Test; + +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +/** + * @author Jeremy Carnus + */ +@TestForIssue(jiraKey = "HHH-12989") +public class InWithHeterogeneousCollectionTest extends BaseCoreFunctionalTestCase { + + @Test + @RequiresDialect(H2Dialect.class) + public void testCaseClause() { + doInHibernate( this::sessionFactory, session -> { + CriteriaBuilder cb = session.getCriteriaBuilder(); + + CriteriaQuery criteria = cb.createQuery( Event.class ); + + Root event = criteria.from( Event.class ); + Path name = event.get( "name" ); + + Expression replaceName = cb.function( + "replace", + String.class, + name, + cb.literal( "a" ), + cb.literal( "a" ) + ); + + criteria.select( event ); + criteria.where( name.in( Arrays.asList( replaceName, "1" ) ) ); + List resultList = session.createQuery( criteria ).getResultList(); + + Assert.assertNotNull( resultList ); + } ); + } + + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { Event.class }; + } + + @Entity(name = "Event") + public static class Event { + + @Id + private Long id; + + @Column + private String name; + + protected Event() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } +} \ No newline at end of file