Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-28737

[GSS](8.0.z) HHH-17151 - NullPointerException happens in Hibernate when setting null value as parameter to Query.setParameter​() with TemporalType parameter

XMLWordPrintable

    • False
    • None
    • False
    • +
    • Workaround Exists
    • Hide

      As the NPE issue does not happen with Query.setParameter() without TemporalType parameter, users can workaround with the following code at this moment:

              // workaround
              if (value != null) {
                  query.setParameter(1, value, TemporalType.TIMESTAMP);
              } else {
                  query.setParameter(1, value);
              }
      
      Show
      As the NPE issue does not happen with Query.setParameter() without TemporalType parameter, users can workaround with the following code at this moment: // workaround if (value != null ) { query.setParameter(1, value, TemporalType.TIMESTAMP); } else { query.setParameter(1, value); }
    • Hide

      1. Deploy kitchensink.war to JBoss EAP 8.0.x. (EAP 8.0.4.1 is the latest at this moment.)
      Copy the attached kitchensink.war to your JBOSS_HOME/stadanlone/deployments/ directory.
      (The application is based on kitchensink in QuickStarts. You can check the source code in kitensink.zip and you can know what was changed for the test case by checking testcase_diff.patch in the zip.)
      2. Start JBoss EAP 8.0.x

      $ ./bin/standalone.sh
      

      3. Access the application with curl command

      $ curl -v localhost:8080/kitchensink/rest/members/0
      

      Then, you will see "500 Internal Server Error" response and the NPE issue occurs in server.log.

      Show
      1. Deploy kitchensink.war to JBoss EAP 8.0.x. (EAP 8.0.4.1 is the latest at this moment.) Copy the attached kitchensink.war to your JBOSS_HOME/stadanlone/deployments/ directory. (The application is based on kitchensink in QuickStarts. You can check the source code in kitensink.zip and you can know what was changed for the test case by checking testcase_diff.patch in the zip.) 2. Start JBoss EAP 8.0.x $ ./bin/standalone.sh 3. Access the application with curl command $ curl -v localhost:8080/kitchensink/ rest /members/0 Then, you will see "500 Internal Server Error" response and the NPE issue occurs in server.log.

      The customer faces NullPointerException issue when setting null value as parameter to Query.setParameter​() after migrating their Java EE application running on JBoss EAP 7.4.x (Hibernate 5.3.x) to Jakarta EE application running on JBoss EAP 8.0.x (Hibernate 6.2.x).
      Note that this NPE issue does not happen with JBoss EAP 7.4.x (Hibernate 5.3.x).

      java.lang.NullPointerException: Cannot invoke "org.hibernate.query.BindableType.resolveExpressible(org.hibernate.engine.spi.SessionFactoryImplementor)" because "declaredParameterType" is null
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.internal.BindingTypeHelper.resolveTemporalPrecision(BindingTypeHelper.java:44)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.internal.QueryParameterBindingImpl.setExplicitTemporalPrecision(QueryParameterBindingImpl.java:295)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.internal.QueryParameterBindingImpl.setBindValue(QueryParameterBindingImpl.java:240)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.spi.AbstractCommonQueryContract.setParameter(AbstractCommonQueryContract.java:1092)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.spi.AbstractSelectionQuery.setParameter(AbstractSelectionQuery.java:882)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.spi.AbstractQuery.setParameter(AbstractQuery.java:607)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.sql.internal.NativeQueryImpl.setParameter(NativeQueryImpl.java:1311)
      	at org.hibernate@6.2.31.Final-redhat-00002//org.hibernate.query.sql.internal.NativeQueryImpl.setParameter(NativeQueryImpl.java:111)
      	at org.jboss.as.jpa@8.0.6.SP1-redhat-00001//org.jboss.as.jpa.container.QueryNonTxInvocationDetacher.setParameter(QueryNonTxInvocationDetacher.java:166)
          ...(snip)...
      

      The NPE happens when setting null value as parameter to Query.setParameter() with TemporalType parameter (= the following methods of jakarta.persistence.Query API:

      • setParameter​(int position, Calendar value, TemporalType temporalType)
      • setParameter​(int position, Date value, TemporalType temporalType)
      • setParameter​(Parameter<Calendar> param, Calendar value, TemporalType temporalType)
      • setParameter​(Parameter<Date> param, Date value, TemporalType temporalType)
      • setParameter​(String name, Calendar value, TemporalType temporalType)
      • setParameter​(String name, Date value, TemporalType temporalType)

      Note that NPE does NOT happen when setting null value as parameter Query.setParameter() without TemporalType parameter (= the following methods of jakarta.persistence.Query API):

      • setParameter​(int position, Object value)
      • setParameter​(String name, Object value)
      • setParameter​(Parameter<T> param, T value)

      A minimum example code that can reproduce the NPE issue is like the following:

              Query query = em.createNativeQuery("update Member set timeStamp = ? where id= ?");
              Date value = null;
              Long id = 1L;
              query.setParameter(1, value, TemporalType.TIMESTAMP); // <-- NPE happens here
              query.setParameter(2, id);
              int res = query.executeUpdate();
      

        1. kitchensink.war
          116 kB
          Masafumi Miura

              lvydra Lukas Vydra
              rhn-support-mmiura Masafumi Miura
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated: