From 01dabaa2de2f976d73d50e56b0348067befa1e4d Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 4 Jul 2023 19:17:58 +0200 Subject: [PATCH] HHH-16875 add a test involving JPQL function() construct --- .../orm/test/query/hql/FunctionTests.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java index 4f2a3567ad..4f57bfed07 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/FunctionTests.java @@ -10,6 +10,7 @@ import org.hibernate.QueryException; import org.hibernate.dialect.CockroachDialect; import org.hibernate.dialect.DB2Dialect; import org.hibernate.dialect.DerbyDialect; +import org.hibernate.dialect.H2Dialect; import org.hibernate.dialect.MariaDBDialect; import org.hibernate.dialect.MySQLDialect; import org.hibernate.dialect.OracleDialect; @@ -1151,6 +1152,24 @@ public class FunctionTests { ); } + @Test + @RequiresDialect(H2Dialect.class) + public void testJpqlFunctionSyntax(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + assertThat( session.createQuery("select function('lower','HIBERNATE')", String.class).getSingleResult(), + equalTo("hibernate") ); + assertThat( session.createQuery("select 1 where function('lower','HIBERNATE') = 'hibernate'", Integer.class).getSingleResult(), + equalTo(1) ); + assertThat( session.createQuery("select function('current_user')", String.class).getSingleResult().toLowerCase(), + isOneOf("hibernate_orm_test", "hibernateormtest", "sa") ); + assertThat( session.createQuery("select lower(function('current_user'))", String.class).getSingleResult(), + isOneOf("hibernate_orm_test", "hibernateormtest", "sa") ); + session.createQuery("select 1 where function('current_user') = 'hibernate_orm_test'", Integer.class).getSingleResultOrNull(); + } + ); + } + @Test public void testTimestampAddDiffFunctions(SessionFactoryScope scope) { scope.inTransaction(