Fix Criteria NPE for named parameters when paramClass is a Collection
This commit is contained in:
parent
0a1527186b
commit
4144c4af4c
|
@ -883,6 +883,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext {
|
||||||
if ( Collection.class.isAssignableFrom( paramClass ) ) {
|
if ( Collection.class.isAssignableFrom( paramClass ) ) {
|
||||||
// a multi-valued parameter
|
// a multi-valued parameter
|
||||||
return new JpaCriteriaParameter(
|
return new JpaCriteriaParameter(
|
||||||
|
name,
|
||||||
new MultiValueParameterType<>( Collection.class ),
|
new MultiValueParameterType<>( Collection.class ),
|
||||||
true,
|
true,
|
||||||
this
|
this
|
||||||
|
@ -892,6 +893,7 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext {
|
||||||
if ( paramClass.isArray() ) {
|
if ( paramClass.isArray() ) {
|
||||||
// an array-valued, multi-valued parameter
|
// an array-valued, multi-valued parameter
|
||||||
return new JpaCriteriaParameter(
|
return new JpaCriteriaParameter(
|
||||||
|
name,
|
||||||
new MultiValueParameterType( Object[].class ),
|
new MultiValueParameterType( Object[].class ),
|
||||||
true,
|
true,
|
||||||
this
|
this
|
||||||
|
|
|
@ -11,13 +11,12 @@ import javax.persistence.criteria.ParameterExpression;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.dialect.DerbyDialect;
|
import org.hibernate.dialect.DerbyDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.dialect.H2Dialect;
|
import org.hibernate.dialect.H2Dialect;
|
||||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||||
import org.hibernate.query.criteria.JpaCriteriaQuery;
|
import org.hibernate.query.criteria.JpaCriteriaQuery;
|
||||||
import org.hibernate.query.criteria.JpaRoot;
|
import org.hibernate.query.criteria.JpaRoot;
|
||||||
|
|
||||||
|
import org.hibernate.testing.SkipForDialect;
|
||||||
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
|
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
|
|
|
@ -6,11 +6,14 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.query.criteria;
|
package org.hibernate.orm.test.query.criteria;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaBuilder;
|
||||||
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.CriteriaQuery;
|
||||||
import javax.persistence.criteria.ParameterExpression;
|
import javax.persistence.criteria.ParameterExpression;
|
||||||
|
import javax.persistence.criteria.Path;
|
||||||
import javax.persistence.criteria.Root;
|
import javax.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
import org.hibernate.query.criteria.HibernateCriteriaBuilder;
|
||||||
|
@ -42,6 +45,28 @@ public class CriteriaParameterTests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNamedParameterBaseline(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction(
|
||||||
|
session -> {
|
||||||
|
final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||||
|
final ParameterExpression<Collection> parameter = criteriaBuilder.parameter( Collection.class, "datas" );
|
||||||
|
final CriteriaQuery<BasicEntity> criteria = criteriaBuilder.createQuery( BasicEntity.class );
|
||||||
|
final Root<BasicEntity> root = criteria.from( BasicEntity.class );
|
||||||
|
Path<?> property = root.get( "data" );
|
||||||
|
criteria.where( property.in( parameter ) );
|
||||||
|
|
||||||
|
final QueryImplementor<BasicEntity> query = session.createQuery( criteria );
|
||||||
|
|
||||||
|
List<String> parameterValue = new ArrayList<>();
|
||||||
|
parameterValue.add( "fe" );
|
||||||
|
|
||||||
|
query.setParameter( "datas", parameterValue );
|
||||||
|
query.list();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMultiValuedParameterBaseline(SessionFactoryScope scope) {
|
public void testMultiValuedParameterBaseline(SessionFactoryScope scope) {
|
||||||
scope.inTransaction(
|
scope.inTransaction(
|
||||||
|
|
Loading…
Reference in New Issue