diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java index 242927ef88..352ee4b3fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/HibernateCriteriaBuilder.java @@ -216,6 +216,16 @@ public interface HibernateCriteriaBuilder extends CriteriaBuilder { */ JpaExpression round(Expression x, Integer n); + /** + * Create an expression that returns the first argument + * truncated to the number of decimal places given by the + * second argument. + * @param x base + * @param n number of decimal places + * @return the truncated value + */ + JpaExpression truncate(Expression x, Integer n); + /** * Create expression to return current local date. * @return expression for current date diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java index 32f6a2f993..4e8991fdbd 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/spi/HibernateCriteriaBuilderDelegate.java @@ -262,6 +262,11 @@ public class HibernateCriteriaBuilderDelegate implements HibernateCriteriaBuilde return criteriaBuilder.round( x, n ); } + @Override + public JpaExpression truncate(Expression x, Integer n) { + return criteriaBuilder.truncate( x, n ); + } + @Override public JpaExpression localDate() { return criteriaBuilder.localDate(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java index f88cef18c0..938f5269f1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmCriteriaNodeBuilder.java @@ -920,6 +920,16 @@ public class SqmCriteriaNodeBuilder implements NodeBuilder, SqmCreationContext, ); } + @Override + public JpaExpression truncate(Expression x, Integer n) { + return getFunctionDescriptor( "truncate" ).generateSqmExpression( + Arrays.asList( (SqmExpression) x, value( n ) ), + null, + queryEngine, + getJpaMetamodel().getTypeConfiguration() + ); + } + @Override public SqmExpression neg(Expression x) { final SqmExpression sqmExpression = (SqmExpression) x;