Spring Boot 需要帮助:引起原因:java.lang.NullPointerException:无法调用“String.contains(java.lang.CharSequence)”,因为“variable”为null

hgc7kmma  于 2023-03-23  发布在  Spring
关注(0)|答案(1)|浏览(1242)

I am trying to upgrade my SpringBoot Version from 2.1.1 to 2.7.x ( 2.7.5){Java Version - 17}, When I try to Run my application , I am getting the following error message
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.(AbstractStringBasedJpaQuery.java:72) at org.springframework.data.jpa.repository.query.NativeJpaQuery.(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) ... 60 common frames omitted
Here are my dependencies:

implementation 'org.springframework.boot:spring-boot:2.7.5'

    implementation('org.springframework.boot:spring-boot-starter-data-jpa')
    implementation('org.springframework.boot:spring-boot-starter-actuator')
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.boot:spring-boot-starter-parent:2.7.5')

    implementation('org.springframework:spring-jdbc')
    implementation('org.springframework:spring-orm')
    implementation('org.springframework:spring-core')
    implementation('org.springframework:spring-beans')
    implementation('org.springframework:spring-webmvc')
    implementation('org.springframework:spring-web')
    implementation('org.springframework:spring-context')
    testImplementation 'org.springframework:spring-test:5.3.25'
    compileOnly group: 'javax.servlet', name: 'servlet-api', version: '2.5'
    runtime("org.springframework.boot:spring-boot-properties-migrator")
    compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
    implementation group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: '9.0.56'
    implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.6.5.Final'
    implementation 'org.springframework.cloud:spring-cloud-context:3.1.0'
    implementation group: 'org.springframework.security', name: 'spring-security-core', version: '5.6.9'
    implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
    implementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.4.0.Final'
    implementation group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
    implementation("net.bytebuddy:byte-buddy:1.14.0")
    compileOnly 'org.projectlombok:lombok:1.18.26'
    annotationProcessor 'org.projectlombok:lombok:1.18.26'

Looking for a fix for this. This block is throwing an error:

@Modifying
    @Transactional
    @Query(value = "INSERT INTO W (CREATED_DATE, PRODUCT_CODE, TENANT_ID, UPDATED_DATE, UUID, STORE_ID) SELECT TO_TIMESTAMP(:createdDate, :format), :productCode, :tenantId, TO_TIMESTAMP(:updatedDate, :format), :uuid, :storeId FROM W WHERE ROWNUM <= 1 AND NOT EXISTS (select * from W w2 WHERE UUID = :uuid  AND PRODUCT_CODE =:productCode)" ,nativeQuery = true)
    int insertIntoW(@Param("format") String format, @Param("createdDate")String createdDate, @Param("productCode")String productCode, @Param("tenantId")String tenantId, @Param("updatedDate") String updatedDate, @Param("uuid")String uuid, @Param("storeId") String storeId);
elcex8rz

elcex8rz1#

我在spring-boot 2.7.9中遇到了同样的问题
在看了这个spring-boot page issue之后,我改变了Spring Boot 版本。版本2.6.6解决了它。

相关问题