openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1509299 - in /openjpa/branches/2.2.x: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
Date Thu, 01 Aug 2013 15:32:24 GMT
Author: jgrassel
Date: Thu Aug  1 15:32:23 2013
New Revision: 1509299

URL: http://svn.apache.org/r1509299
Log:
OPENJPA-2267: native query select with null result causes NullPointerException

Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
    openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java?rev=1509299&r1=1509298&r2=1509299&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
Thu Aug  1 15:32:23 2013
@@ -199,7 +199,7 @@ public class ResultPacker {
      * Pack the given object into an instance of the query's result class.
      */
     public Object pack(Object result) {
-        if (_resultClass == result.getClass())
+        if (result == null || _resultClass == result.getClass())
             return result;
         // special cases for efficient basic types where we want to avoid
         // creating an array for call to general pack method below

Modified: openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java?rev=1509299&r1=1509298&r2=1509299&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
(original)
+++ openjpa/branches/2.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
Thu Aug  1 15:32:23 2013
@@ -31,6 +31,7 @@ import org.apache.openjpa.persistence.te
 
 public class TestNativeQueries extends SingleEMFTestCase {
     private static final String TABLE_NAME = "entity_1";
+    private static final String TABLE_NAME_2 = "ENTITY2";
     private static final String CONST_NAME = "testSimple";
     private static final int CONST_INT = 42;
     
@@ -148,6 +149,11 @@ public class TestNativeQueries extends S
         assertEquals("abc", q.getHints().get(hintKey));
         
     }
+    
+    public void testNullResult() {
+        String sql = "SELECT max(pk) FROM " + TABLE_NAME_2+ "";
+        assertNull(em.createNativeQuery(sql, Long.class).getSingleResult());
+    }
 
     public void assertSize(int num, List l) {
         assertNotNull(l);



Mime
View raw message