Hibernate Criteria API throws org.hibernate.QueryException: CAST function should only have 2 arguments

            Expression<String> confidenceScorePath = builder.function("jsonb_extract_path_text", String.class, root.get("metrics"), builder.literal("confidence_score"));

if(operator.equalsIgnoreCase(GREATER_THAN)){
                confidenceScorePredicates.add(builder.gt(confidenceScorePath.as(Double.class), value));
            }
            if(operator.equalsIgnoreCase(GREATER_THAN_EQUAL)){
                confidenceScorePredicates.add(builder.ge(confidenceScorePath.as(Double.class), value));
            }

the above is the logic where I’m casting it to Double using criteria Builder but i see the below error as CAST function allows only 2 args kindly help

{"timestamp":"2024-Aug-02 22:34:37.876","severity":"ERROR","thread":"http-nio-8080-exec-3","debug_file":"DirectJDKLog.java", "debug_line":"175","message":"Servlet.service() for servlet [dispatcherServlet] in context with path [/api] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: CAST function should only have 2 arguments [select generatedAlias0 from com.rakuten.observability.core.entities.PlatformModelInference as generatedAlias0 where ( ( generatedAlias0.modelId=6 ) and ( generatedAlias0.versionNumber=:param0 ) and ( generatedAlias0.dataSetId in (1, 2) ) and ( 1=1 ) and ( ( ( 0=1 ) or ( function('jsonb_extract_path_text', generatedAlias0.groundTruths, :param1)=:param2 ) ) or ( function('jsonb_extract_path_text', generatedAlias0.groundTruths, :param3)=:param4 ) ) and ( generatedAlias0.createdAt between :param5 and :param6 ) and ( cast(function('jsonb_extract_path_text', generatedAlias0.metrics, :param7) as double)>=0.0D ) ) and ( 1=1 ) order by generatedAlias0.id desc]] with root cause"}
org.hibernate.QueryException: CAST function should only have 2 arguments

This might be a bug, please try to create a test case and if you are able to reproduce the issue, create a new ticket in our issue tracker and attach that reproducer.

Note that the as expression on criteria expressions is not meant to type conversion (i.e. a cast) on the database side, see the method’s javadoc. If that’s what you want, you should instead use HibernateCriteriaBuilder’s cast method instead.