I just tried to call the ‘extract’-Function inside hibernate 6’s CriteriaBuilder like so:
Expression yearExtractParameter = cb.literal(TemporalUnit.YEAR);
Predicate p1 = cb.le(cb.function(“extract”, Integer.class, yearExtractParameter, root.get(“startDate”)), lookupYear);
Getting the below ClassCastException, also tried String-typed literal.
Is there a way to create a time-unit parameter that translates to an SqmExtractUnit?
Help will be greatly appreciated!
java.lang.ClassCastException: class org.hibernate.query.sqm.tree.expression.SqmLiteral cannot be cast to class org.hibernate.query.sqm.tree.expression.SqmExtractUnit (org.hibernate.query.sqm.tree.expression.SqmLiteral and org.hibernate.query.sqm.tree.expression.SqmExtractUnit are in unnamed module of loader ‘app’)
at org.hibernate.dialect.function.ExtractFunction.generateSqmFunctionExpression(ExtractFunction.java:85)
at org.hibernate.query.sqm.function.AbstractSqmFunctionDescriptor.generateSqmExpression(AbstractSqmFunctionDescriptor.java:104)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.function(SqmCriteriaNodeBuilder.java:1705)
at org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder.function(SqmCriteriaNodeBuilder.java:192)