Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ public MappingModelExpressible<?> resolveFunctionArgumentType(
}
}
else if ( argumentIndex == 1 ) {
final SqmTypedNode<?> nodeToResolve = function.getArguments().get( 1 );
if ( nodeToResolve.getExpressible() instanceof MappingModelExpressible<?> ) {
// If the node already has suitable type, don't infer it to be treated as an array
return null;
}
final SqmTypedNode<?> node = function.getArguments().get( 0 );
if ( node instanceof SqmExpression<?> ) {
final MappingModelExpressible<?> expressible = converter.determineValueMapping( (SqmExpression<?>) node );
if ( expressible != null ) {
if ( expressible instanceof BasicPluralType<?, ?> ) {
return expressible;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2886,11 +2886,14 @@ else if ( inListContext instanceof HqlParser.ArrayInListContext ) {

final SqmExpression<?> arrayExpr = (SqmExpression<?>) arrayInListContext.expression().accept( this );
final SqmExpressible<?> arrayExpressible = arrayExpr.getExpressible();
if ( arrayExpressible != null && !( arrayExpressible.getSqmType() instanceof BasicPluralType<?, ?>) ) {
throw new SemanticException(
"Right operand for in-array predicate must be a basic plural type expression, but found: " + arrayExpressible.getSqmType(),
query
);
if ( arrayExpressible != null ) {
if ( !(arrayExpressible.getSqmType() instanceof BasicPluralType<?, ?>) ) {
throw new SemanticException(
"Right operand for in-array predicate must be a basic plural type expression, but found: " + arrayExpressible.getSqmType(),
query
);
}
testExpression.applyInferableType( ( (BasicPluralType<?, ?>) arrayExpressible.getSqmType() ).getElementType() );
}
final SelfRenderingSqmFunction<Boolean> contains = getFunctionDescriptor( "array_contains" ).generateSqmExpression(
asList( arrayExpr, testExpression ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
Expand Down Expand Up @@ -157,4 +158,22 @@ public void testInSyntax(SessionFactoryScope scope) {
} );
}

@Test
@JiraKey( "HHH-18851" )
public void testInArray(SessionFactoryScope scope) {
scope.inSession( em -> {
List<Tuple> results = em.createQuery(
"select e.id " +
"from EntityWithArrays e " +
"where :p in e.theArray",
Tuple.class
)
.setParameter( "p", "abc" )
.getResultList();

assertEquals( 1, results.size() );
assertEquals( 2L, results.get( 0 ).get( 0 ) );
} );
}

}
Loading