with Hibernate-core from 6.6.0.Final to 6.6.4.Final I’m having a problem using criteriaBuilder.like() to find a list of students whose idSecond field (which is an integer) contains the string ‘171’;
my code works fine with Hibernate-core 6.5.3.Final
Predicate[] buildCriterias(CriteriaBuilder criteriaBuilder, Root<Student> c) {
...
List<Predicate> predicats = new ArrayList<>();
predicats.add(criteriaBuilder.like(c.get("idSecond").as(String.class), "%171%"));
...
}
Hint: No operator matches the given name and argument types.
You need to add explicit type casts.
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer ~~ text
and when I add an explicit cast.
predicats.add(criteriaBuilder.like(
criteriaBuilder.function("CAST", String.class, c.get("idSecond")),
"%171"%"
));
this time I get this error:
org.hibernate.query.sqm.produce.function.FunctionArgumentException: Function cast() has 2 parameters, but 1 arguments given
at org.hibernate.query.sqm.produce.function.StandardArgumentsValidators$4.validate(StandardArgumentsValidators.java:114) ~[hibernate-core-6.6.4.Final.jar:6.6.4.Final]
would you have an idea
Thank you