Skip to content

Incorrect alias detect for query if parameter contains "from" path #2535

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

Closed
PiryazevAlex opened this issue May 19, 2022 · 3 comments
Closed
Assignees
Labels
status: superseded An issue that has been superseded by another

Comments

@PiryazevAlex
Copy link

I have a query with parameter named periodFrom. So i have an error if i pass order parameter to JPA repository method

Page<Some> findSome(LocalDate periodFrom, Pageable pageable);

After debug, I found bug in org.springframework.data.jpa.repository.query.QueryUtils.

import org.junit.jupiter.api.Test;
import org.springframework.data.jpa.repository.query.QueryUtils;

public class QueryUtilsTest {
    @Test
    void queryUtilsWrongAliasDetection(){
        final String query = "select p from Some p where (:periodFrom is null or p.periodFrom = :periodFrom)";
        final String actual = QueryUtils.detectAlias(query);
        assertEquals("p", actual);
    }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 19, 2022
@edudar
Copy link
Contributor

edudar commented May 19, 2022

Fixed in #2521

@gregturn gregturn self-assigned this May 19, 2022
@gregturn gregturn removed the status: waiting-for-triage An issue we've not yet triaged label May 19, 2022
@gregturn
Copy link
Contributor

gregturn commented May 19, 2022

The core issue is #2260 (#2521 was the related PR).

Indeed, this issue now passes...

@Test // GH-2535
void queryUtilsWrongAliasDetection() {
	assertThat(QueryUtils.detectAlias("select p from Some p where (:periodFrom is null or p.periodFrom = :periodFrom)"))
			.isEqualTo("p");
}

The release with this patch went out last Friday (https://spring.io/blog/2022/05/13/spring-data-2021-2-and-2022-0-m4-released).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 19, 2022
@gregturn gregturn added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged labels May 19, 2022
@PiryazevAlex
Copy link
Author

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

4 participants