Closed julgus closed 1 year ago
The issue is how we copy restrictions from the original Criteria when building the count Criteria. These restrictions are associated with a certain Path
element that cannot be reused from one Criteria to another.
if (criteriaQuery.getRestriction() != null) {
countQuery.where(criteriaQuery.getRestriction());
}
I fixed it by recreating the predicate from the internal pipeline. This adds a bit of redundant work but seems like the simplest solution at this point.
if (!filters.isEmpty()) {
// There can only be one JPAStreamer filter after the filter merge (see FilterCriteriaModifier).
IntermediateOperation<?, ?> filter = filters.stream().findFirst().get();
this.<T>getPredicate(filter).ifPresent(speedmentPredicate -> {
final Predicate predicate = predicateFactory.createPredicate(countCriteria, speedmentPredicate);
countQuery.where(predicate);
});
}
Describe the bug When performing repeated
.count()
queries, an exception is thrown. This seems to be related to differences between Hibernate 5 and 6, and how JPAStreamer reuses certain Criteria objects when creating the queries.Expected behavior The query should execute without exceptions.
Actual behavior The query yields an exception, see below.
How To Reproduce Performing the following test reveals the exception:
Exception:
Build tool e.g. Maven 3.9.0
JPAStreamer version e.g. JPAStreamer 3.0.2
JPA Provider e.g. Hibernate 6.0.2.Final
Java Version e.g. Java 11.0.17
Additional context The thread that potentially explains the issue: https://hibernate.atlassian.net/browse/HHH-15951?jql=project%20%3D%20HHH%20AND%20component%20%3D%20hibernate-entitymanager%20AND%20resolution%20%3D%20Unresolved%20AND%20fixVersion%20is%20EMPTY%20ORDER%20BY%20priority%20DESC.