-
Notifications
You must be signed in to change notification settings - Fork 1.5k
NullPointerException
in version 3.0.2 when using modifying native queries or SELECT
queries that Spring Data cannot parse
#2812
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
Comments
Also affects A simple test for @Test
void nativeUpdateQueryThrowsException() {
DeclaredQuery declaredQuery = DeclaredQuery.of("delete from some_table where id in :ids", true);
QueryEnhancer enhancer = createQueryEnhancer(declaredQuery);
assertThatNoException().isThrownBy(() -> enhancer.createCountQueryFor(null));
} "Offending" query itself can be also:
|
In my case, the NPE occurs querying a sequence value. @Query(value = "SELECT nexval('public.my_sequence')", nativeQuery = true)
Integer getNextvalMySequence(); |
Same here, with non CRUD native query (spring-jpa 2.7.8) @Query(value = """
select count(1) as totalItems,
sum(case when myField is null then 0 else 1 end) as notNullItems
from myClass
""", nativeQuery = true) Found a workaround by adding a fictive @Query(value = """
select count(1) as totalItems,
sum(case when myField is null then 0 else 1 end) as notNullItems
from myClass
""", countQuery = "select 1", nativeQuery = true) |
Same with an UPDATE query in 2.7.9: @Modifying
@Query(nativeQuery = true, value = "UPDATE seq_mgmt SET seq_no = :value WHERE seq_id = :key")
int setNextValue(@Param("key") String key, @Param("value") Long value); |
We now delay the count query creation to the actual time when we need the count query to avoid query creation of invalid queries (e.g. count queries for DELETE or UPDATE statements). See #2812
We now delay the count query creation to the actual time when we need the count query to avoid query creation of invalid queries (e.g. count queries for DELETE or UPDATE statements). See #2812
We now delay the count query creation to the actual time when we need the count query to avoid query creation of invalid queries (e.g. count queries for DELETE or UPDATE statements). See #2812
We now delay the count query creation to the actual time when we need the count query to avoid query creation of invalid queries (e.g. count queries for DELETE or UPDATE statements). See #2812
This has been patched in |
Is this warranting a release of SDJPA asap, or is it still within your release cadence? If not re-releasing ASAP, when is the next release? I'm not aware of the cadence this project follows. Thanks! |
Workaround for people using Gradle if you don't want to downgrade Spring Boot altogether: configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'spring-data-jpa' && details.requested.version == '3.0.2') {
details.useVersion '3.0.1'
details.because 'https://github.com/spring-projects/spring-data-jpa/issues/2812'
}
}
} |
I'm still experiencing this issue in version 3.0.4-SNAPSHOT, 3.1.0-SNAPSHOT and 2.7.10-SNAPSHOT. Is there anything else I should do or check to resolve this using the SNAPSHOT version? |
@otavioprado we released just today versions |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Unfortunately the last stable version is 2.7.8 |
If you use Spring Boot 2.7.9: Spring Data BOM 2021.2.9 has been released, with Spring Data 2.7.9. This will be included in Spring Boot 2.7.10 (scheduled for March 23), but you can temporarily override |
Thanks @breun
To use spring-boot 3.0.3 I need to upgrade the bom to 2022.0.3 ? |
@otavioprado You don’t even need that full import, this should be enough:
If you’re on Spring Boot 3, you can upgrade to Spring Boot 3.0.4, which was just released. |
2.7.9 can't parse this
2.7.8 is Ok mysql dialect |
According to my experience even a simple insert statement does not work with 2.7.9:
This was okay with 2.7.8. |
@pfuerholz Are you referring to Spring Boot 2.7.9 or Spring Data JPA 2.7.9? This bug should have been fixed in the latter. |
Thanks for pointing this out. spring-boot-starter-data-jpa 2.7.9 is actually using spring-data-jpa 2.7.8
|
When I use version 2.7.9 throughout Spring Boot. |
Works on |
When I use version 2.7.10 throughout Spring Boot it works! |
Commit 64b5a22 introduced a null pointer exception in line 620 of QueryUtils. If a native query is not a select, but, for example, a delete, "variable" will be null, leading to said exception.
Example code in repository:
Relevant part of the trace:
The text was updated successfully, but these errors were encountered: