According to https://discourse.hibernate.org/t/criteriabuilder-cast-function-example/6631/4 there is a solution using cast instead of as:
cast
as
var cast = ((JpaExpression) from.get("uuid")).cast(String.class); cb.like(cast, "%" + stringValue + "%");