We are migrating from springboot 2.5 to the latest 3.1.0, which means hibernate migration 5.x to 6.x.
I have below code which use two classes 'CriteriaBuilderImpl' and 'ComparisonPredicate', which I think are removed in hibernate 6.x. As I have read the migration guides (https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.0:-Hibernate-ORM-5-to-6-migration#legacy-criteria) which calls for an action => Migrate existing code that relies on legacy Hibernate Criteria API to the JPA Criteria API.
Can someone please suggest how the below code can be migrated to be hibernate 6.x comptatible ? As of now with springboot 3.1.0, the below code gives me 'cannot find symbol' for the above two classes. Thanks in advance.
import org.hibernate.query.criteria.internal.CriteriaBuilderImpl;
import org.hibernate.query.criteria.internal.predicate.ComparisonPredicate;
private Specification<ProductDAO> getSpecFromDatesAndExample(CriteriaBuilder builder, Date startDate, Date endDate) {
final List<Predicate> predicates = new ArrayList<>();
predicates.add(new ComparisonPredicate((CriteriaBuilderImpl) builder,
ComparisonPredicate.ComparisonOperator.GREATER_THAN, root.get("startDate"), startDate));
predicates.add(new ComparisonPredicate((CriteriaBuilderImpl) builder,
ComparisonPredicate.ComparisonOperator.LESS_THAN, root.get("endDate"), endDate));
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
}
I found the methods greaterThan(), lessThan() in CriteriaBuilder that I have used.
For example,
predicates.add(new ComparisonPredicate((CriteriaBuilderImpl) builder,
ComparisonPredicate.ComparisonOperator.GREATER_THAN, root.get("startDate"), startDate));
updated to,
predicates.add(builder.greaterThan(root.get("startDate"), startDate);
Hope this helps someone!