最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Batching in criteriaQuery is throwing exception while migrating from Hibernate 5 ->6 - Stack Overflow

programmeradmin6浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论