openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curti...@apache.org
Subject svn commit: r1391218 - in /openjpa/trunk: 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, 27 Sep 2012 21:05:08 GMT
Author: curtisr7
Date: Thu Sep 27 21:05:07 2012
New Revision: 1391218

URL: http://svn.apache.org/viewvc?rev=1391218&view=rev
Log:
OPENJPA-2267: Fix NPE in ResultPacker when there is a null result.

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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java?rev=1391218&r1=1391217&r2=1391218&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
Thu Sep 27 21:05:07 2012
@@ -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/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java?rev=1391218&r1=1391217&r2=1391218&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
Thu Sep 27 21:05:07 2012
@@ -31,6 +31,8 @@ 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 +150,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