Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-17976 - Add test and avoid potential NPE #8267

Closed
wants to merge 1 commit into from
Closed
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 @@ -13,6 +13,7 @@
import org.hibernate.metamodel.mapping.MappingModelExpressible;
import org.hibernate.metamodel.model.domain.DomainType;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
import org.hibernate.query.sqm.tree.SqmTypedNode;
import org.hibernate.sql.ast.tree.SqlAstNode;
Expand Down Expand Up @@ -58,17 +59,19 @@ else if ( inferredType instanceof BasicValuedMapping ) {
}
if ( elementIndex == -1 ) {
for ( SqmTypedNode<?> argument : arguments ) {
final DomainType<?> sqmType = argument.getExpressible().getSqmType();
if ( sqmType instanceof ReturnableType<?> ) {
final SqmExpressible<?> expressible;
final DomainType<?> sqmType;
if ( (expressible = argument.getExpressible()) != null && ( sqmType = expressible.getSqmType() ) instanceof ReturnableType<?> ) {
return list
? DdlTypeHelper.resolveListType( sqmType, typeConfiguration )
: DdlTypeHelper.resolveArrayType( sqmType, typeConfiguration );
}
}
}
else {
final DomainType<?> sqmType = arguments.get( elementIndex ).getExpressible().getSqmType();
if ( sqmType instanceof ReturnableType<?> ) {
final SqmExpressible<?> expressible;
final DomainType<?> sqmType;
if ( (expressible = arguments.get( elementIndex ).getExpressible()) != null && ( sqmType = expressible.getSqmType() ) instanceof ReturnableType<?> ) {
return list
? DdlTypeHelper.resolveListType( sqmType, typeConfiguration )
: DdlTypeHelper.resolveArrayType( sqmType, typeConfiguration );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Collection;
import java.util.List;

import org.hibernate.query.Query;
import org.hibernate.query.criteria.JpaCriteriaQuery;
import org.hibernate.query.criteria.JpaRoot;
import org.hibernate.query.sqm.NodeBuilder;
Expand Down Expand Up @@ -107,6 +108,29 @@ public void testOverlapsNull(SessionFactoryScope scope) {
} );
}

@Test
public void testOverlapsFullyWithOneOrdinalParam(SessionFactoryScope scope) {
scope.inSession( em -> {
Query<EntityWithArrays> q = em.createQuery( "from EntityWithArrays e where array_overlaps(e.theCollection, array(cast(?1 as String), 'def'))", EntityWithArrays.class );
q.setParameter( 1, "abc" );
List<EntityWithArrays> results = q.getResultList();
assertEquals( 1, results.size() );
assertEquals( 2L, results.get( 0 ).getId() );
} );
}

@Test
public void testOverlapsFullyWithAllOrdinalParams(SessionFactoryScope scope) {
scope.inSession( em -> {
Query<EntityWithArrays> q = em.createQuery( "from EntityWithArrays e where array_overlaps(e.theCollection, array(cast(?1 as String), cast(?2 as String)))", EntityWithArrays.class );
q.setParameter( 1, "abc" );
q.setParameter( 2, "def" );
List<EntityWithArrays> results = q.getResultList();
assertEquals( 1, results.size() );
assertEquals( 2L, results.get( 0 ).getId() );
} );
}

@Test
public void testNodeBuilderArray(SessionFactoryScope scope) {
scope.inSession( em -> {
Expand Down