HHH-17912 Disallow multiple valued binding for BasicCollectionType
This commit is contained in:
parent
b4603e0e40
commit
71234d90ae
|
@ -22,6 +22,7 @@ import org.hibernate.query.sqm.tree.SqmStatement;
|
|||
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper;
|
||||
import org.hibernate.query.sqm.tree.expression.SqmParameter;
|
||||
import org.hibernate.type.BasicCollectionType;
|
||||
|
||||
/**
|
||||
* Maintains a cross-reference between SqmParameter and QueryParameter references.
|
||||
|
@ -90,6 +91,9 @@ public class DomainParameterXref {
|
|||
queryParameter.disallowMultiValuedBinding();
|
||||
}
|
||||
}
|
||||
else if ( sqmParameter.getExpressible() != null && sqmParameter.getExpressible().getSqmType() instanceof BasicCollectionType ) {
|
||||
queryParameter.disallowMultiValuedBinding();
|
||||
}
|
||||
|
||||
sqmParamsByQueryParam.computeIfAbsent( queryParameter, qp -> new ArrayList<>() ).add( sqmParameter );
|
||||
queryParamBySqmParam.put( sqmParameter, queryParameter );
|
||||
|
|
|
@ -13,6 +13,8 @@ import jakarta.persistence.Table;
|
|||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An entity with multiple attributes of basic type for use in testing using those types/attributes
|
||||
* in queries.
|
||||
|
@ -29,6 +31,8 @@ public class MultiTypedBasicAttributesEntity {
|
|||
private int[] someInts;
|
||||
private Integer[] someWrappedIntegers;
|
||||
|
||||
private List<Integer> integerList;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -52,4 +56,12 @@ public class MultiTypedBasicAttributesEntity {
|
|||
public void setSomeWrappedIntegers(Integer[] someWrappedIntegers) {
|
||||
this.someWrappedIntegers = someWrappedIntegers;
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerList() {
|
||||
return integerList;
|
||||
}
|
||||
|
||||
public void setIntegerList(List<Integer> integerList) {
|
||||
this.integerList = integerList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,10 @@ import jakarta.persistence.criteria.Path;
|
|||
import jakarta.persistence.criteria.Root;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
|
||||
|
@ -150,6 +149,25 @@ public class ParameterTest extends BaseEntityManagerFunctionalTestCase {
|
|||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-17912")
|
||||
public void testAttributeEqualListParameter() {
|
||||
TransactionUtil.doInJPA( this::entityManagerFactory, em -> {
|
||||
final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
|
||||
final CriteriaQuery<MultiTypedBasicAttributesEntity> criteria = criteriaBuilder
|
||||
.createQuery( MultiTypedBasicAttributesEntity.class );
|
||||
|
||||
final ParameterExpression<List> parameter = criteriaBuilder.parameter( List.class );
|
||||
|
||||
final Root<MultiTypedBasicAttributesEntity> root = criteria.from( MultiTypedBasicAttributesEntity.class );
|
||||
criteria.select( root ).where( criteriaBuilder.equal( root.get( MultiTypedBasicAttributesEntity_.integerList ), parameter ) );
|
||||
|
||||
final TypedQuery<MultiTypedBasicAttributesEntity> query1 = em.createQuery( criteria );
|
||||
query1.setParameter( parameter, List.of( 1, 2, 3 ) );
|
||||
query1.getResultList();
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { MultiTypedBasicAttributesEntity.class };
|
||||
|
|
Loading…
Reference in New Issue