File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
test/java/org/hibernate/orm/test/function/array Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,15 @@ public class ArrayContainsArgumentTypeResolver extends AbstractFunctionArgumentT
4343 }
4444 }
4545 else if ( argumentIndex == 1 ) {
46+ final SqmTypedNode <?> nodeToResolve = arguments .get ( 1 );
47+ if ( nodeToResolve .getExpressible () instanceof MappingModelExpressible <?> ) {
48+ // If the node already has suitable type, don't infer it to be treated as an array
49+ return null ;
50+ }
4651 final SqmTypedNode <?> node = arguments .get ( 0 );
4752 if ( node instanceof SqmExpression <?> ) {
4853 final MappingModelExpressible <?> expressible = converter .determineValueMapping ( (SqmExpression <?>) node );
49- if ( expressible != null ) {
54+ if ( expressible instanceof BasicPluralType <?, ?> ) {
5055 return expressible ;
5156 }
5257 }
Original file line number Diff line number Diff line change @@ -3391,12 +3391,15 @@ else if ( inListContext instanceof HqlParser.ArrayInListContext arrayInListConte
33913391
33923392 final SqmExpression <?> arrayExpr = (SqmExpression <?>) arrayInListContext .expression ().accept ( this );
33933393 final SqmExpressible <?> arrayExpressible = arrayExpr .getExpressible ();
3394- if ( arrayExpressible != null && !( arrayExpressible .getSqmType () instanceof BasicPluralType <?, ?>) ) {
3395- throw new SemanticException (
3396- "Right operand for in-array predicate must be a basic plural type expression, but found: "
3394+ if ( arrayExpressible != null ) {
3395+ if ( !(arrayExpressible .getSqmType () instanceof BasicPluralType <?, ?> pluralType ) ) {
3396+ throw new SemanticException (
3397+ "Right operand for in-array predicate must be a basic plural type expression, but found: "
33973398 + arrayExpressible .getSqmType (),
3398- query
3399- );
3399+ query
3400+ );
3401+ }
3402+ testExpression .applyInferableType ( pluralType .getElementType () );
34003403 }
34013404 final SelfRenderingSqmFunction <Boolean > contains = getFunctionDescriptor ( "array_contains" ).generateSqmExpression (
34023405 asList ( arrayExpr , testExpression ),
Original file line number Diff line number Diff line change 1515import org .hibernate .testing .orm .junit .BootstrapServiceRegistry ;
1616import org .hibernate .testing .orm .junit .DialectFeatureChecks ;
1717import org .hibernate .testing .orm .junit .DomainModel ;
18+ import org .hibernate .testing .orm .junit .JiraKey ;
1819import org .hibernate .testing .orm .junit .RequiresDialectFeature ;
1920import org .hibernate .testing .orm .junit .SessionFactory ;
2021import org .hibernate .testing .orm .junit .SessionFactoryScope ;
@@ -156,4 +157,22 @@ public void testInSyntax(SessionFactoryScope scope) {
156157 } );
157158 }
158159
160+ @ Test
161+ @ JiraKey ( "HHH-18851" )
162+ public void testInArray (SessionFactoryScope scope ) {
163+ scope .inSession ( em -> {
164+ List <Tuple > results = em .createQuery (
165+ "select e.id " +
166+ "from EntityWithArrays e " +
167+ "where :p in e.theArray" ,
168+ Tuple .class
169+ )
170+ .setParameter ( "p" , "abc" )
171+ .getResultList ();
172+
173+ assertEquals ( 1 , results .size () );
174+ assertEquals ( 2L , results .get ( 0 ).get ( 0 ) );
175+ } );
176+ }
177+
159178}
You can’t perform that action at this time.
0 commit comments