OpenJPA
  1. OpenJPA
  2. OPENJPA-2267

native query select with null result causes NullPointerException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2.0, 2.3.0
    • Fix Version/s: 2.3.0
    • Component/s: query
    • Labels:
      None
    • Environment:
      my system is fedora 16, MySql 5.5.18 (running innodb), jdk1.6.0_26, openjdk 2.2.0 (also happened in 2.1.0), mysql-connector-java 5.1.18, commons-dbcp 1.4, spring 3.1.1

      Description

      if you do a native query with a null resultset where the resulting object is not the model object, it causes a null pointer exception.

      ---------------------------------------------------

      mysql> desc Data;
      ------------------------------------------------------------------+

      Field Type Null Key Default Extra

      ------------------------------------------------------------------+

      id bigint(20) NO PRI NULL auto_increment
      data mediumblob YES   NULL  

      ------------------------------------------------------------------+
      12 rows in set (0.01 sec)

      mysql> select count from Data;
      ----------

      count

      ----------

      0

      ----------
      1 row in set (0.00 sec)

      mysql> select max(id) from Data;
      ---------

      max(id)

      ---------

      NULL

      ---------
      1 row in set (0.00 sec)

      now in java do :

      Query query = entityManager.createNativeQuery("select max(id) from Data", Long.class);
      List results = query.getResultList();

      The following exception ensues.

      ---------------------------------------------------

      <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(id) from Data". Check the query syntax for correctness. See nested exception for details.
      at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
      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)
      ...
      Caused by: java.lang.NullPointerException
      at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:202)
      at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
      at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
      at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
      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)

        Issue Links

          Activity

          Mark Struberg made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Jody Grassel made changes -
          Link This issue duplicates OPENJPA-2195 [ OPENJPA-2195 ]
          Rick Curtis made changes -
          Affects Version/s 2.3.0 [ 12319463 ]
          Rick Curtis made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.3.0 [ 12319463 ]
          Resolution Fixed [ 1 ]
          Rick Curtis made changes -
          Assignee Rick Curtis [ curtisr7 ]
          Ted Leung made changes -
          Description if you do a native query with a null resultset where the resulting object is not the model object, it causes a null pointer exception.

          ---------------------------------------------------

          mysql> select count(*) from Data;
          +----------+
          | count(*) |
          +----------+
          | 0 |
          +----------+
          1 row in set (0.00 sec)

          mysql> select max(id) from Data;
          +---------+
          | max(id) |
          +---------+
          | NULL |
          +---------+
          1 row in set (0.00 sec)

          now in java do :

          Query query = entityManager.createNativeQuery("select max(id) from Data", Long.class);
          List results = query.getResultList();

          The following exception ensues.

          ---------------------------------------------------

          <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(id) from Data". Check the query syntax for correctness. See nested exception for details.
          at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
          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)
          ...
          Caused by: java.lang.NullPointerException
          at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:202)
          at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
          at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
          at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
          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)
          if you do a native query with a null resultset where the resulting object is not the model object, it causes a null pointer exception.

          ---------------------------------------------------

          mysql> desc Data;
          +--------------------------+--------------+------+-----+---------+----------------+
          | Field | Type | Null | Key | Default | Extra |
          +--------------------------+--------------+------+-----+---------+----------------+
          | id | bigint(20) | NO | PRI | NULL | auto_increment |
          | data | mediumblob | YES | | NULL | |
          +--------------------------+--------------+------+-----+---------+----------------+
          12 rows in set (0.01 sec)

          mysql> select count(*) from Data;
          +----------+
          | count(*) |
          +----------+
          | 0 |
          +----------+
          1 row in set (0.00 sec)

          mysql> select max(id) from Data;
          +---------+
          | max(id) |
          +---------+
          | NULL |
          +---------+
          1 row in set (0.00 sec)

          now in java do :

          Query query = entityManager.createNativeQuery("select max(id) from Data", Long.class);
          List results = query.getResultList();

          The following exception ensues.

          ---------------------------------------------------

          <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(id) from Data". Check the query syntax for correctness. See nested exception for details.
          at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
          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)
          ...
          Caused by: java.lang.NullPointerException
          at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:202)
          at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
          at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
          at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
          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)
          Ted Leung made changes -
          Field Original Value New Value
          Description if you do a native query with a null resultset where the resulting object is not the model object, it causes a null pointer exception.

          ---------------------------------------------------

          mysql> select count(*) from Data;
          +----------+
          | count(*) |
          +----------+
          | 0 |
          +----------+
          1 row in set (0.00 sec)

          mysql> select max(id) from Data;
          +---------+
          | max(id) |
          +---------+
          | NULL |
          +---------+
          1 row in set (0.00 sec)

          now in java do :

          Query query = entityManager.createNativeQuery("select max(id) from Data", Long.class);
          List results = query.getResultList();

          The following exception ensues.

          ---------------------------------------------------

          <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(id) from MedicalData". Check the query syntax for correctness. See nested exception for details.
          at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
          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)
          ...
          Caused by: java.lang.NullPointerException
          at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:202)
          at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
          at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
          at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
          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)
          if you do a native query with a null resultset where the resulting object is not the model object, it causes a null pointer exception.

          ---------------------------------------------------

          mysql> select count(*) from Data;
          +----------+
          | count(*) |
          +----------+
          | 0 |
          +----------+
          1 row in set (0.00 sec)

          mysql> select max(id) from Data;
          +---------+
          | max(id) |
          +---------+
          | NULL |
          +---------+
          1 row in set (0.00 sec)

          now in java do :

          Query query = entityManager.createNativeQuery("select max(id) from Data", Long.class);
          List results = query.getResultList();

          The following exception ensues.

          ---------------------------------------------------

          <openjpa-2.2.0-r422266:1244990 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Failed to execute query "select max(id) from Data". Check the query syntax for correctness. See nested exception for details.
          at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:872)
          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)
          ...
          Caused by: java.lang.NullPointerException
          at org.apache.openjpa.kernel.ResultPacker.pack(ResultPacker.java:202)
          at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(SQLProjectionResultObjectProvider.java:88)
          at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(RangeResultObjectProvider.java:80)
          at org.apache.openjpa.lib.rop.EagerResultList.<init>(EagerResultList.java:36)
          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)
          Ted Leung created issue -

            People

            • Assignee:
              Rick Curtis
              Reporter:
              Ted Leung
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development