openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgras...@apache.org
Subject svn commit: r1508983 - in /openjpa/branches/2.1.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 Wed, 31 Jul 2013 18:30:57 GMT
Author: jgrassel
Date: Wed Jul 31 18:30:57 2013
New Revision: 1508983

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

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

Modified: openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java?rev=1508983&r1=1508982&r2=1508983&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
(original)
+++ openjpa/branches/2.1.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ResultPacker.java
Wed Jul 31 18:30:57 2013
@@ -189,7 +189,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.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java?rev=1508983&r1=1508982&r2=1508983&view=diff
==============================================================================
--- openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
(original)
+++ openjpa/branches/2.1.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/mapping/TestNativeQueries.java
Wed Jul 31 18:30:57 2013
@@ -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