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

Nullpointer Exception when using native query #2819

Closed
schnandr opened this issue Feb 23, 2023 · 4 comments
Closed

Nullpointer Exception when using native query #2819

schnandr opened this issue Feb 23, 2023 · 4 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@schnandr
Copy link

schnandr commented Feb 23, 2023

Following repository worked in 3.0.1.

public interface SomeRepository extends JpaRepository<Request, Integer> {

  @Query(value = "SELECT usf_request_number();", nativeQuery = true)
  int usfRequestNumber();

}

With 3.0.2 (spring boot 3.0.3) I am getting a Nullpointer in QueryUtils.createCountQueryFor that variable is null.

Cannot invoke "String.contains(java.lang.CharSequence)" because "variable" is null

Maybe related to this fix: #2773

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 23, 2023
@gideruette
Copy link

gideruette commented Feb 23, 2023

I think this is duplicate of #2812

@uthark
Copy link

uthark commented Feb 23, 2023

I see the same issue after upgrading to spring boot 2.7.9

Caused by: java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "variable" is null
        at org.springframework.data.jpa.repository.query.QueryUtils.createCountQueryFor(QueryUtils.java:607)
        at org.springframework.data.jpa.repository.query.DefaultQueryEnhancer.createCountQueryFor(DefaultQueryEnhancer.java:49)
        at org.springframework.data.jpa.repository.query.StringQuery.deriveCountQuery(StringQuery.java:119)
        at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.<init>(AbstractStringBasedJpaQuery.java:72)
        at org.springframework.data.jpa.repository.query.NativeJpaQuery.<init>(NativeJpaQuery.java:53)
        at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:51)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:169)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:253)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:103)
        ... 122 common frames omitted

@aldingithub
Copy link

Same issue after upgrading to spring boot 3.0.3

Caused by: java.lang.NullPointerException: Cannot invoke "String.contains(java.lang.CharSequence)" because "variable" is null
        at org.springframework.data.jpa.repository.query.QueryUtils.createCountQueryFor(QueryUtils.java:607)
        at org.springframework.data.jpa.repository.query.DefaultQueryEnhancer.createCountQueryFor(DefaultQueryEnhancer.java:49)
        at org.springframework.data.jpa.repository.query.StringQuery.deriveCountQuery(StringQuery.java:119)
        at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.<init>(AbstractStringBasedJpaQuery.java:72)
        at org.springframework.data.jpa.repository.query.NativeJpaQuery.<init>(NativeJpaQuery.java:53)
        at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:51)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:169)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:253)
        at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:93)
        at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.lookupQuery(QueryExecutorMethodInterceptor.java:103)
        ... 122 common frames omitted
        ```

@schnandr
Copy link
Author

Duplicates #2812

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

5 participants