0
java.lang.NullPointerException: null
    at org.hibernate.loader.custom.sql.NamedParamBinder.bind(NamedParamBinder.java:34)
    at org.hibernate.loader.custom.CustomLoader.bindParameterValues(CustomLoader.java:475)
    at org.hibernate.loader.Loader.bindPreparedStatement(Loader.java:2169)
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2146)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2078)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2056)
    at org.hibernate.loader.Loader.doQuery(Loader.java:953)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:350)
    at org.hibernate.loader.Loader.doList(Loader.java:2887)
    at org.hibernate.loader.Loader.doList(Loader.java:2869)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2701)
    at org.hibernate.loader.Loader.list(Loader.java:2696)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2142)
    at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1163)
    at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:173)
    at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533)
    at org.hibernate.query.Query.getResultList(Query.java:165)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:409)
    at com.sun.proxy.$Proxy292.getResultList(Unknown Source)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:126)
    at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154)
    at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152)
    at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:367)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)

I get above error after upgrading Spring Boot from 1.5.x to 2.2.2. I believe this has upgraded the Hibernate version too, and that might cause above error. I'm not sure if this is a bug in Hibernate

Should I downgrade my Hibernate version by specifying in gradle? Rather then using the default one which Spring Boot 2.2.2 provides?

Is it a defect in Hibernate 5.x?

The program start successfully. It gives the error when the program tries to execute the native query; syntax looks like below

    @Query(value = " SELECT ds.* FROM DocumentSimilarity AS ds INNER JOIN CompanyDocumentInfo AS hi ON hi.companyDocumentInfoID = ds.companyDocumentInfoID AND hi.isDeleted=:isDeleted AND hi.siteID=:siteID AND hi.clientID=:clientID  " +
            "WHERE        (ds.processStatus =:documentProcessStatus) AND (hi.processStatus =:similarityProcessStatus) AND (hi.excelProcessStatus in:eXcelProcessStatus) order by ds.modifiedDate /*#pageable*/", countQuery = "select count(modifiedDate) from DocumentSimilarity order by modifiedDate /*#pageable*/ ", nativeQuery = true)
    List<DocumentSimilarity> getSimilarityRecordForExcel(@Param("clientID") int clientID, @Param("siteID") String siteID, @Param("documentProcessStatus") String documentProcessStatus, @Param("isDeleted") int isDeleted, @Param("eXcelProcessStatus") List<String> excelProcessStatus, @Param("similarityProcessStatus") String similarityProcessStatus, Pageable pageable);

Findings

When it tries to execute below

final TypedValue typedValue = qp.getNamedParameters().get( name );
typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );

typedValue is null, name ="eXcelProcessStatus"

I have correctly spelled eXcelProcessStatus as this is in database table and in my Entity class

Below is the value in

qp.getNamedParameters()

{documentProcessStatus=PROCESSED, clientID=1, isDeleted=0, similarityProcessStatus=NOPROCESS, siteID=3}

It does not contain eXcelProcessStatus, I'm not sure if this has something to do with X (uppercase) in eXcelProcessStatus

More findings.

I have also tried lowering X in @param(name=excelProcessStatus), but I still get the same error.

Hibernate versions :
hibernate-core-5.4.20.Final.jar
hibernate-validator-6.1.5.Final.jar
hibernate-commons-annotations-5.1.0.Final.jar
hibernate-c3p0-5.4.21.Final.jar

Mark Rotteveel
  • 82,132
  • 136
  • 114
  • 158
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Oozeerally Sep 07 '20 at 13:21
  • @AdilOoze i am sorry didn't you get the trace and the details that i added. Just don't answer randomly – Viral Kondhia Sep 08 '20 at 06:11
  • When do you get that exception? Does not the program run at start or it gives the error when you do sth. specific? Please tell the steps to reproduce the error – Onur Baştürk Sep 08 '20 at 06:42
  • @OnurBaştürk Yes the program starts I am adding the details in question – Viral Kondhia Sep 08 '20 at 07:24
  • What is the exact Hibernate version? What are the values of the parameters when the exception is thrown? Can you debug it in your IDE - put a breakpoint on `NamedParamBinder.bind(NamedParamBinder.java:34)` and see on which parameter does it throw the exception? – Adam Michalik Sep 08 '20 at 08:02
  • @AdamMichalik already did that debugging. Added some findings on the question. -Thanks – Viral Kondhia Sep 08 '20 at 08:47
  • I see multiple people report that passing list parameters to native queries only works for some combination of JPA library and DB driver. See these questions: https://stackoverflow.com/questions/21484176/ https://stackoverflow.com/questions/6277807/ – Adam Michalik Sep 08 '20 at 09:15
  • @AdamMichalik can be.... Nevertheless i have added the answer which is working for me. – Viral Kondhia Sep 08 '20 at 09:41

1 Answers1

0

Not sure if this is due to the the upgrade but doing following changes in the query ( which is a gigantic change ) [space]

instead of

(hi.excelProcessStatus in:eXcelProcessStatus)

doing this (hi.excelProcessStatus in: eXcelProcessStatus)

has solved the problem. Issue seems to be with just [space].

Writing method like this

@Query(value = " SELECT ds.* FROM DocumentSimilarity AS ds INNER JOIN CompanyDocumentInfo AS hi ON hi.companyDocumentInfoID = ds.companyDocumentInfoID AND hi.isDeleted=:isDeleted AND hi.siteID=:siteID AND hi.clientID=:clientID  " +
            "WHERE        (ds.processStatus =:documentProcessStatus) AND (hi.processStatus =:similarityProcessStatus) AND (hi.excelProcessStatus in: eXcelProcessStatus) order by ds.modifiedDate /*#pageable*/", countQuery = "select count(modifiedDate) from DocumentSimilarity order by modifiedDate /*#pageable*/ ", nativeQuery = true)
    List<DocumentSimilarity> getSimilarityRecordForExcel(@Param("clientID") int clientID, @Param("siteID") String siteID, @Param("documentProcessStatus") String documentProcessStatus, @Param("isDeleted") int isDeleted, @Param("eXcelProcessStatus") List<String> excelProcessStatus, @Param("similarityProcessStatus") String similarityProcessStatus, Pageable pageable);