diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java index 97450dfec0..3d0bec4226 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/DerbyDialect.java @@ -72,7 +72,6 @@ import java.sql.Types; import jakarta.persistence.TemporalType; -import static org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers.useArgType; import static org.hibernate.type.SqlTypes.*; /** @@ -249,13 +248,9 @@ public class DerbyDialect extends Dialect { functionFactory.leftRight_substrLength(); functionFactory.characterLength_length( SqlAstNodeRenderingMode.NO_PLAIN_PARAMETER ); functionFactory.power_expLn(); + functionFactory.round_floor(); functionFactory.bitLength_pattern( "length(?1)*8" ); - queryEngine.getSqmFunctionRegistry().patternDescriptorBuilder( "round", "floor(?1*1e?2+0.5)/1e?2") - .setReturnTypeResolver( useArgType(1) ) - .setExactArgumentCount( 2 ) - .register(); - queryEngine.getSqmFunctionRegistry().register( "concat", new CastingConcatFunction( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index 6738c563c3..4b54c7e155 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -404,6 +404,7 @@ public class PostgreSQLDialect extends Dialect { CommonFunctionFactory functionFactory = new CommonFunctionFactory(queryEngine); + functionFactory.round_floor(); //Postgres round(x,n) does not accept double functionFactory.cot(); functionFactory.radians(); functionFactory.degrees(); @@ -602,13 +603,9 @@ public class PostgreSQLDialect extends Dialect { return false; } - /** - * Workaround for postgres bug #1453 - *

- * {@inheritDoc} - */ @Override public String getSelectClauseNullString(int sqlType) { + // Workaround for postgres bug #1453 return "null::" + getRawTypeName( sqlType ); } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java index 6d4a32066b..7f9051cc77 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/function/CommonFunctionFactory.java @@ -1883,6 +1883,14 @@ public class CommonFunctionFactory { .register(); } + public void round_floor() { + functionRegistry.patternDescriptorBuilder( "round", "floor(?1*1e?2+0.5)/1e?2") + .setReturnTypeResolver( useArgType(1) ) + .setExactArgumentCount( 2 ) + .setParameterTypes(NUMERIC, INTEGER) + .register(); + } + public void square() { functionRegistry.namedDescriptorBuilder( "square" ) .setExactArgumentCount( 1 ) 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 24e3053aa2..79517add72 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 @@ -282,6 +282,8 @@ public class FunctionTests { .list(); session.createQuery("select ceiling(e.theDouble), floor(e.theDouble) from EntityOfBasics e") .list(); + session.createQuery("select round(e.theDouble, 2) from EntityOfBasics e") + .list(); session.createQuery("select round(cast(e.theDouble as BigDecimal), 3) from EntityOfBasics e") .list(); assertThat( session.createQuery("select abs(-2)").getSingleResult(), is(2) );