openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Leung (JIRA)" <>
Subject [jira] [Created] (OPENJPA-2267) native query select with null result causes NullPointerException
Date Wed, 26 Sep 2012 02:30:07 GMT
Ted Leung created OPENJPA-2267:

             Summary: native query select with null result causes NullPointerException
                 Key: OPENJPA-2267
             Project: OpenJPA
          Issue Type: Bug
          Components: query
    Affects Versions: 2.2.0
         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
            Reporter: Ted Leung
            Priority: Minor

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(
	at org.apache.openjpa.kernel.QueryImpl.execute(
	at org.apache.openjpa.kernel.DelegatingQuery.execute(
	at org.apache.openjpa.persistence.QueryImpl.execute(
	at org.apache.openjpa.persistence.QueryImpl.getResultList(
Caused by: java.lang.NullPointerException
	at org.apache.openjpa.kernel.ResultPacker.pack(
	at org.apache.openjpa.jdbc.kernel.SQLProjectionResultObjectProvider.getResultObject(
	at org.apache.openjpa.lib.rop.RangeResultObjectProvider.getResultObject(
	at org.apache.openjpa.lib.rop.EagerResultList.<init>(
	at org.apache.openjpa.kernel.QueryImpl.toResult(
	at org.apache.openjpa.kernel.QueryImpl.execute(
	at org.apache.openjpa.kernel.QueryImpl.execute(

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:

View raw message