From a5bfed34b4a0d95dbd8dc16032d7d7e5ddf2e71e Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Mon, 18 Mar 2024 19:07:54 +0100 Subject: [PATCH] HHH-17801 Resolve enum basic types to avoid type validation issues --- .../internal/InferredBasicValueResolver.java | 5 ++++- .../test/function/array/ArrayPositionTest.java | 11 +++++++++++ .../orm/test/function/array/EntityWithArrays.java | 15 +++++++++++++++ .../hibernate/orm/test/function/array/Label.java | 14 ++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/function/array/Label.java diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java index d30a48c4d2..20cd61c624 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java @@ -295,7 +295,10 @@ public class InferredBasicValueResolver { final JdbcType jdbcType = explicitJdbcType == null ? enumJavaType.getRecommendedJdbcType( stdIndicators ) : explicitJdbcType; - final BasicTypeImpl basicType = new BasicTypeImpl<>( enumJavaType, jdbcType ); + final BasicType basicType = bootstrapContext.getTypeConfiguration().getBasicTypeRegistry().resolve( + enumJavaType, + jdbcType + ); bootstrapContext.registerAdHocBasicType( basicType ); return new InferredBasicValueResolution<>( basicType, diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java index 26a8a97645..be357b8f07 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/ArrayPositionTest.java @@ -8,6 +8,7 @@ package org.hibernate.orm.test.function.array; import java.util.Collection; import java.util.List; +import java.util.Set; import org.hibernate.query.criteria.JpaCriteriaQuery; import org.hibernate.query.criteria.JpaRoot; @@ -17,6 +18,7 @@ import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator 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.Jira; import org.hibernate.testing.orm.junit.RequiresDialectFeature; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; @@ -85,6 +87,15 @@ public class ArrayPositionTest { } ); } + @Test + @Jira("https://hibernate.atlassian.net/browse/HHH-17801") + public void testEnumPosition(SessionFactoryScope scope) { + scope.inSession( em -> { + em.createQuery( "from EntityWithArrays e where array_position(e.theLabels, e.theLabel) > 0", EntityWithArrays.class ) + .getResultList(); + } ); + } + @Test public void testNodeBuilderArray(SessionFactoryScope scope) { scope.inSession( em -> { diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/EntityWithArrays.java b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/EntityWithArrays.java index 350baa9c91..c03c1e76f3 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/EntityWithArrays.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/function/array/EntityWithArrays.java @@ -8,6 +8,7 @@ package org.hibernate.orm.test.function.array; import java.util.List; +import java.util.Set; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -24,6 +25,12 @@ public class EntityWithArrays { @Column(name = "the_array", insertable = false, updatable = false) private List theCollection; + @Column(name = "the_label") + private Label theLabel; + + @Column(name = "the_labels") + private Set