I am facing some Parameter Binding issue:
java.lang.IllegalArgumentException: Cannot create binding for parameter reference [.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter@a19fe87]
- reference is not a parameter of this query
when we try to migrate to hibernate 6 in the following method:
public List<A> findByListOfSubDocumentsAndDateRange(
final List<String> subDocuments,
final Date effDate,
final Date endDate
) {
final Session session = getSessionFactory().getCurrentSession();
final CriteriaBuilder builder = session.getCriteriaBuilder();
final CriteriaQuery<A> criteria = builder.createQuery(A.class);
final Root<A> root = criteria.from(A.class);
// Split input list into batches of 1000 items
final int batchSize = 1000;
List<A> results = new ArrayList<>();
for (int i = 0; i < subDocuments.size(); i += batchSize) {
List<String> batchList = subDocuments.subList(i, Math.min(i + batchSize, subDocuments.size()));
// Create predicates
List<Predicate> predicates = new ArrayList<>();
predicates.add(root.get(PRIMARY_KEY).get(COLUMN1).in(batchList));
predicates.add(builder.lessThanOrEqualTo(root.get(PRIMARY_KEY).get(COLUMN2), effDate));
if (endDate != null) {
predicates.add(builder.greaterThanOrEqualTo(root.get(PRIMARY_KEY).get(COLUMN_ENDDATE), endDate));
}
criteria.select(root).where(predicates.toArray(new Predicate[0]));
// Execute batch query and collect results
results.addAll(session.createQuery(criteria).getResultList());
}
return results;
}
Here we are performing batching in order to improve performance of the query this piece of logic was working fine in HIbernate 5 but is not working in hibernate 6 and error is bit ambiguous because when I remove the for loop the Integration test works only when adding the batching it didn't work. Any ideas on how to resolve this issue. I tried to check Hibernate 6 Docs couldn't find the cause for this issue.