Skip to content
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

QueryDslPredicateExecutor + EntityGraph + findAll [DATAJPA-684] #1061

Closed
spring-projects-issues opened this issue Mar 3, 2015 · 7 comments
Closed
Assignees
Labels
status: duplicate type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Mar 3, 2015

Björn Häuser opened DATAJPA-684 and commented

When overriding the findAll(…) method of QueryDslPredicateExecutor with an @EntityGraph the query fails with:

org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list

What is the easiest way to provide a (non) working example? Sorry when I did something wrong, thats my first JIRA issue for Spring.


Affects: 1.7.2 (Evans SR2)

Reference URL: http://stackoverflow.com/questions/27494988/overriding-spring-data-jpa-default-method-annotating-with-entitygraph-causes-que

Issue Links:

  • DATAJPA-790 org.hibernate.QueryException when applying @EntityGraph on (Querydsl) findAll(Predicate, Pageable) method
    ("duplicates")

3 votes, 4 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 3, 2015

Oliver Drotbohm commented

A most minimal example Maven project with a failing test case would be perfect. The StackOverflow post you linked seems to be caused by a mismatch of the fetch graph and the predicates, i.e. properties referred to in the predicate which are not included in the fetch graph

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 6, 2015

Björn Häuser commented

Sorry, I took me a while, but here is the demo: https://github.com/bjoernhaeuser/jpa-684-demo

Clone it, run it and than go to http://localhost:8080/notworking (you get the same exception), http://localhost:8080/working uses the entitygraph. The problem seems to be the Pageable parameter, for reference: https://github.com/bjoernhaeuser/jpa-684-demo/blob/master/src/main/java/demo/Controller.java

Thanks!

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 8, 2015

Oliver Drotbohm commented

Does the example really make sense? What is BooleanBuilder supposed to restrict on?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 8, 2015

Björn Häuser commented

I updated the repository to contain a more meaningful expression. So the example make a little bit sense now.

Thank you

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Mar 16, 2016

Alex K commented

I ran into the same issue - http://stackoverflow.com/questions/36043665/querydsl-query-specified-join-fetching-but-the-owner-of-the-fetched-associati and would like to confirm that the fix described at the following SO question http://stackoverflow.com/questions/27494988/overriding-spring-data-jpa-default-method-annotating-with-entitygraph-causes-que works at the first look - perfect!

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Apr 30, 2016

Alex K commented

It also can be fixed in the following way:

Original

QueryDslJpaRepository.findAll(Predicate predicate, Pageable pageable

)

method can be changed to following one:

@Override
	public Page<T> findAll(Predicate predicate, Pageable pageable) {

		final JPQLQuery<?> countQuery = createCountQuery(predicate);
		final JPQLQuery<T> query = querydsl.applyPagination(pageable, createQuery(predicate).select(path));

		final long total = countQuery.fetchCount();
		final List<T> content = pageable == null || total > pageable.getOffset() ? query.fetch() : Collections.<T> emptyList();

		return new PageImpl<T>(content, pageable, total);
	}

	private JPQLQuery<?> createCountQuery(Predicate predicate) {
        	return querydsl.createQuery(path).where(predicate);
    	}

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 22, 2019

Jens Schauder commented

Batch closing resolved issue without a fix version and a resolution indicating that there is nothing to release (Won't fix, Invalid ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate type: bug
Projects
None yet
Development

No branches or pull requests

2 participants