-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"The owner of the fetched association was not present in the select list" error on SimpleJpaRepository#getCountQuery #3765
Comments
Please provide a minimal yet complete sample that reproduces the problem. JPA's Criteria API doesn't allow removing fetch joins, the CriteriaBuilder is only additive in its nature. With Spring Data JPA 3.5 we're introducing a method to provide a count specification, see #3727. |
Here's the sample: Instructions to reproduce are in the README file. |
@marcioggs thanks, but that's returning |
Ops, sorry. |
Thank you for the reproducer. The issue is the same as when using plain JPA directly as outlined below (simplified for readability). CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> criteriaQuery = cb.createQuery(Long.class);
Root<TaskList> root = criteriaQuery.from(TaskList.class);
Join<TaskList, TaskItem> join = root.fetch("taskItems");
criteriaQuery.where(cb.equal(join.get("description"), "Report issue"));
criteriaQuery.select(cb.count(root));
TypedQuery<Long> query = em.createQuery(criteriaQuery);
// same as before but:
// omit .select(cb.count(root)) allows entity manager to create query
Join<TaskList, TaskItem> join = root.fetch("taskItems");
criteriaQuery.where(cb.equal(join.get("description"), "Report issue"));
TypedQuery<Long> query = em.createQuery(criteriaQuery);
((SelectionQuery<?>) query).getResultCount(); If you consider reporting the issue back to the hibernate team make sure to provide a sample that solely consists of hibernate and JPA to avoid being filtered out by your choice of technology. |
Thank you @christophstrobl . |
Hi.
I'm having the error in the stack trace below using sprint-data-jpa 3.4.2 when calling JpaSpecificationExecutor#findAll(@Nullable Specification spec, Pageable pageable).
The specification being passed as an argument contains a fetch join (such as
root.fetch(Entity_.attribute, JoinType.LEFT)
).The exception is thrown by SimpleJpaRepository#getCountQuery(@Nullable Specification<S> spec, Class<S> domainClass) when the entity manager tries to create the query.
Should the
getCountQuery
method remove the fetch from fetch joins before requesting the entity manager to create the query?It seems to be related to issue 2348.
Sample:
https://github.com/marcioggs/spring-data-jpa-issue-3765-sample
Thank you.
The text was updated successfully, but these errors were encountered: