Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2565

org.apache.openjpa.persistence.PersistenceException: NULL IS NOT VALID IN THE CONTEXT WHERE IT IS USED.

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.2, 2.3.0
    • Fix Version/s: None
    • Component/s: jpa, kernel, query, sql
    • Labels:
      None
    • Environment:
      server side:
      db2 on z/os version 10.5

      client side:
      eclipse jee 4.2
      jdk1.6.0_30
      jee 6
      Driver: IBM Data Server Driver for JDBC and SQLJ 4.12.72 (jdbc driver)
      openjpa 2.2.2

      Description

      We encountered the following error log when processing the results of a query that its parameter set with null pointer (junit test method)..
      db2 10.5 for z/os
      openjpa 2.2.2

      Thanks,
      codoka
      -------------error log----------------------
      <openjpa-2.2.2-r422266:1468616 fatal general error> org.apache.openjpa.persistence.PersistenceException: NULL IS NOT VALID IN THE CONTEXT WHERE IT IS USED. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.12.72

      {prepstmnt 561094448 SELECT t0.ID, t0.NAME, t0.INSERT_TIME, t0.UPDATE_TIME FROM UNI.DEPT t0 WHERE (1 = 1 OR t0.ID IN (NULL)) }

      [code=-206, state=42703]SQLCA OUTPUT[Errp=DSNXORSO, Errd=-100, 0, 0, -1, 0, 0]
      NULL IS NOT VALID IN THE CONTEXT WHERE IT IS USED. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.12.72
      null
      SQL_CURLH200C1
      FailedObject: SELECT d FROM entities.Dept d where ?1 is null or d.id in (?1) [java.lang.String]
      at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4962)
      at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4922)
      at org.apache.openjpa.jdbc.sql.DB2Dictionary.newStoreException(DB2Dictionary.java:570)
      at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
      at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:118)
      at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:70)
      at org.apache.openjpa.jdbc.kernel.SelectResultObjectProvider.handleCheckedException(SelectResultObjectProvider.java:155)
      at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:40)
      at org.apache.openjpa.kernel.QueryImpl.toResult(QueryImpl.java:1251)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1007)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      at queries.tests.FindByDeptIdTest.testPrintAllDeptsNameWhenDeptIdsIsNull(FindByDeptIdTest.java:84)

      --------------junit test method------------

      @Test
      public void testPrintAllDeptsNameWhenDeptIdsIsNull() {
      try {
      EntityManagerFactory emf = Persistence.createEntityManagerFactory("uni-pu");
      EntityManager em = emf.createEntityManager();
      em.getTransaction().begin();
      Query query = em.createQuery("SELECT d FROM entities.Dept d where ?1 is null or d.id in (?1)");
      List<Integer> deptIds = null;
      query.setParameter(1, deptIds);
      List<Dept> depts = (List<Dept>) query.getResultList();
      for (Dept d : depts)

      { System.out.println(d.getName()); }

      em.close();
      emf.close();
      assertTrue(true);
      } catch (Exception e)

      { e.printStackTrace(); assertTrue(false); }

      }

      -------------- persistance.xml file-----------
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/"
      version="1.0">

      <persistence-unit name="uni-pu" transaction-type="RESOURCE_LOCAL">
      <provider>org.apache.openjpa.persistence.PersistenceProviderImpl
      </provider>
      <class>entities.Dept</class>
      <properties>
      <property name="openjpa.jdbc.DBDictionary" value="db2" />
      <property name="javax.persistence.jdbc.user" value="uni" />
      <property name="javax.persistence.jdbc.password" value="uni" />
      <property name="openjpa.ConnectionURL"
      value="jdbc:db2://192.168.1.110:50000/UNI:retrieveMessagesFromServerOnGetMessage=true;emulateParameterMetaDataForZCalls=1;" />
      <property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver" />
      <property name="openjpa.Log" value="DefaultLevel=TRACE,Runtime=TRACE,Tool=TRACE,SQL=TRACE" />
      </properties>
      </persistence-unit>
      </persistence>
      ------------------------------------------------------

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jahadsa kafku codoka
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: