In Hibernate prior to version 6.6.1 it seemed to worked as @Dinesh describes.
queryBuilder.desc(root.get("room").get("id")).as(Integer.class))
Since Hibernate 6.6.1 this has changed: https://docs.jboss.org/hibernate/orm/6.6/migration-guide/migration-guide.html#criteria-query
Current usage is following:
((JpaExpression)queryBuilder.desc(root.get("room").get("id"))).cast(Integer.class))