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

Spring Data JPA generates incorrect JPQL query for pagination request #2969

Closed
sergey-morenets opened this issue May 23, 2023 · 2 comments
Closed
Assignees
Labels
in: query-parser Everything related to parsing JPQL or SQL type: regression A regression from a previous release

Comments

@sergey-morenets
Copy link

Hi

We upgraded our project to Spring Data JPA 3.1 and found new error. We have StoryRepository with method findStories:

	@Query("FROM Story WHERE enabled = true")
	List<Story> findStories(Pageable pageRequest);

And we invoke it in our service:

	Pageable pageable = limit > 0 ? PageRequest.of(0, limit)
			: PageRequest.of(0, Integer.MAX_VALUE, Sort.by(Direction.DESC, "created"));
	return storyRepository.findStories(pageable);

It worked before upgrade but now we got an exception:

Caused by: org.hibernate.query.sqm.ParsingException: line 1:45 mismatched input '.' expecting {<EOF>, ',', '+', '-', '*', '/', '%', '||', ASC, BY, DAY, DESC, EPOCH, FETCH, HOUR, LIMIT, MINUTE, MONTH, NANOSECOND, NULLS, OFFSET, QUARTER, SECOND, WEEK, YEAR}

Here's JPQL query generated by Spring Data:

FROM Story WHERE enabled = true order by null.created desc

Interesting is that if we change our repository query to

@Query("SELECT p FROM Story p WHERE p.enabled = true")

then everything works correctly.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 23, 2023
gregturn added a commit that referenced this issue May 23, 2023
…ixed.

In the event a Hibernate query doesn't have a primary alias, don't attempt to prefix order by property settings.

See #2969
@gregturn gregturn self-assigned this May 23, 2023
@gregturn gregturn added type: regression A regression from a previous release in: query-parser Everything related to parsing JPQL or SQL and removed status: waiting-for-triage An issue we've not yet triaged labels May 23, 2023
@gregturn gregturn added this to the 3.2 M1 (2023.1.0) milestone May 23, 2023
@gregturn
Copy link
Contributor

Confirmed. The fix is pretty easy.

gregturn added a commit that referenced this issue May 23, 2023
…ixed.

If a Hibernate query doesn't have a primary alias, don't attempt to prefix any Sort properties using it.

See #2969
Original Pull Request #2971
gregturn added a commit that referenced this issue May 23, 2023
…ixed.

If a Hibernate query doesn't have a primary alias, don't attempt to prefix any Sort properties using it.

See #2969
Original Pull Request #2971
@gregturn
Copy link
Contributor

Merged to main and backported to 3.1.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: query-parser Everything related to parsing JPQL or SQL type: regression A regression from a previous release
Projects
None yet
3 participants