diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java index 1b44af0f944..2de663be1b3 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/InformixDialect.java @@ -57,6 +57,7 @@ import org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy; import org.hibernate.query.sqm.mutation.spi.SqmMultiTableInsertStrategy; import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; +import org.hibernate.query.sqm.produce.function.StandardFunctionArgumentTypeResolvers; import org.hibernate.query.sqm.sql.SqmTranslator; import org.hibernate.query.sqm.sql.SqmTranslatorFactory; import org.hibernate.query.sqm.sql.StandardSqmTranslatorFactory; @@ -76,6 +77,7 @@ import org.hibernate.tool.schema.internal.StandardTableExporter; import org.hibernate.tool.schema.spi.Exporter; import org.hibernate.type.JavaObjectType; +import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.jdbc.ClobJdbcType; import org.hibernate.type.descriptor.jdbc.ObjectNullAsBinaryTypeJdbcType; import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry; @@ -88,6 +90,7 @@ import jakarta.persistence.TemporalType; import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate; +import static org.hibernate.query.sqm.produce.function.FunctionParameterType.STRING; import static org.hibernate.type.SqlTypes.BIGINT; import static org.hibernate.type.SqlTypes.BINARY; import static org.hibernate.type.SqlTypes.FLOAT; @@ -333,7 +336,7 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio functionFactory.stddev(); functionFactory.variance(); functionFactory.bitLength_pattern( "length(?1)*8" ); - + if ( getVersion().isSameOrAfter( 12 ) ) { functionFactory.locate_charindex(); } @@ -342,6 +345,20 @@ public void initializeFunctionRegistry(FunctionContributions functionContributio functionContributions.getFunctionRegistry().register( "least", new CaseLeastGreatestEmulation( true ) ); functionContributions.getFunctionRegistry().register( "greatest", new CaseLeastGreatestEmulation( false ) ); + functionContributions.getFunctionRegistry().namedDescriptorBuilder( "matches" ) + .setInvariantType( functionContributions.getTypeConfiguration() + .getBasicTypeRegistry() + .resolve( StandardBasicTypes.STRING ) + ) + .setExactArgumentCount( 2 ) + .setArgumentTypeResolver( + StandardFunctionArgumentTypeResolvers.impliedOrInvariant( + functionContributions.getTypeConfiguration(), + STRING + ) + ) + .setArgumentListSignature( "(STRING string, STRING pattern)" ) + .register(); if ( supportsWindowFunctions() ) { functionFactory.windowFunctions(); } diff --git a/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixFunctionTest.java b/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixFunctionTest.java index 29ab032044b..ec1c686aa55 100644 --- a/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixFunctionTest.java +++ b/hibernate-community-dialects/src/test/java/org/hibernate/community/dialect/InformixFunctionTest.java @@ -179,6 +179,23 @@ public void testCurrentTimestamp(SessionFactoryScope scope) { ); } + @Test + @JiraKey( value = "HHH-18369" ) + public void testMatches(SessionFactoryScope scope) { + scope.inTransaction( + (session) -> { + String country = (String) session.createQuery( + "select e.country " + + "from Event e " + + "where e.id = :id and matches(e.country, :country) = 'T'" ) + .setParameter( "id", event.id ) + .setParameter( "country", "R*" ) + .getSingleResult(); + assertEquals( "Romania", country ); + } + ); + } + private Calendar todayCalendar() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 0);