Skip to content

Commit 9bf4fad

Browse files
committed
HHH-19490 Apply review feedbacks and fix testcase to work well with H2
1 parent 92c82d8 commit 9bf4fad

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/function/array/ArrayAndElementArgumentValidator.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public void validate(
3838
if ( elementIndex < arguments.size() ) {
3939
final SqmTypedNode<?> elementArgument = arguments.get( elementIndex );
4040
final SqmBindableType<?> expressible = elementArgument.getExpressible();
41-
if (expressible == null) {
42-
return;
43-
}
44-
final SqmExpressible<?> elementType = expressible.getSqmType();
41+
final SqmExpressible<?> elementType = expressible != null ? expressible.getSqmType() : null;
4542
if ( expectedElementType != null && elementType != null && expectedElementType != elementType ) {
4643
throw new FunctionArgumentException(
4744
String.format(

hibernate-core/src/test/java/org/hibernate/orm/test/query/QuerySelectWhereArrayPositionTest.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import jakarta.persistence.Entity;
88
import jakarta.persistence.GeneratedValue;
99
import jakarta.persistence.Id;
10-
import org.hibernate.dialect.PostgreSQLDialect;
10+
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1111
import org.hibernate.testing.orm.junit.DomainModel;
1212
import org.hibernate.testing.orm.junit.JiraKey;
13-
import org.hibernate.testing.orm.junit.RequiresDialect;
13+
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1414
import org.hibernate.testing.orm.junit.SessionFactory;
1515
import org.hibernate.testing.orm.junit.SessionFactoryScope;
16+
import org.junit.jupiter.api.AfterAll;
1617
import org.junit.jupiter.api.BeforeEach;
1718
import org.junit.jupiter.api.Test;
1819

@@ -26,7 +27,8 @@
2627
}
2728
)
2829
@SessionFactory
29-
@RequiresDialect( PostgreSQLDialect.class )
30+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsStructuralArrays.class)
31+
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsArrayPositions.class)
3032
@JiraKey("HHH-19490")
3133
public class QuerySelectWhereArrayPositionTest {
3234
@BeforeEach
@@ -40,15 +42,20 @@ public void setUp(SessionFactoryScope scope) {
4042
);
4143
}
4244

45+
@AfterAll
46+
public void tearDown(SessionFactoryScope scope) {
47+
scope.getSessionFactory().getSchemaManager().truncateMappedObjects();
48+
}
49+
4350
@Test
4451
public void testSelectWhereArrayPosition(SessionFactoryScope scope) {
4552
scope.inTransaction( session -> {
4653
List<TestEntity> result = session.createQuery( "select testEntity "
4754
+ "from TestEntity testEntity "
48-
+ "where ARRAY_POSITION(testEntity.values, ?1) IS NOT NULL", TestEntity.class )
49-
.setParameter( 1, 3)
55+
+ "where ARRAY_POSITION(testEntity.numbers, ?1) > 0", TestEntity.class )
56+
.setParameter( 1, 2 )
5057
.getResultList();
51-
assertThat( result.size() ).isEqualTo( 3 );
58+
assertThat( result.size() ).isEqualTo( 2 );
5259
} );
5360
}
5461

@@ -59,13 +66,13 @@ public static class TestEntity {
5966
@GeneratedValue
6067
private Long id;
6168

62-
private List<Integer> values;
69+
private List<Integer> numbers;
6370

6471
public TestEntity() {
6572
}
6673

67-
public TestEntity(List<Integer> values) {
68-
this.values = values;
74+
public TestEntity(List<Integer> numbers) {
75+
this.numbers = numbers;
6976
}
7077
}
7178
}

0 commit comments

Comments
 (0)