mirror of https://github.com/apache/openjpa.git
OPENJPA-2267: native query select with null result causes NullPointerException
git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.1.x@1508983 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c47104b95f
commit
6f36f2af34
|
@ -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
|
||||
|
|
|
@ -31,6 +31,8 @@ import org.apache.openjpa.persistence.test.SingleEMFTestCase;
|
|||
|
||||
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 SingleEMFTestCase {
|
|||
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);
|
||||
|
|
Loading…
Reference in New Issue