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.
|
* Pack the given object into an instance of the query's result class.
|
||||||
*/
|
*/
|
||||||
public Object pack(Object result) {
|
public Object pack(Object result) {
|
||||||
if (_resultClass == result.getClass())
|
if (result == null || _resultClass == result.getClass())
|
||||||
return result;
|
return result;
|
||||||
// special cases for efficient basic types where we want to avoid
|
// special cases for efficient basic types where we want to avoid
|
||||||
// creating an array for call to general pack method below
|
// 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 {
|
public class TestNativeQueries extends SingleEMFTestCase {
|
||||||
private static final String TABLE_NAME = "entity_1";
|
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 String CONST_NAME = "testSimple";
|
||||||
private static final int CONST_INT = 42;
|
private static final int CONST_INT = 42;
|
||||||
|
|
||||||
|
@ -149,6 +151,11 @@ public class TestNativeQueries extends SingleEMFTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
public void assertSize(int num, List l) {
|
||||||
assertNotNull(l);
|
assertNotNull(l);
|
||||||
assertEquals(num, l.size());
|
assertEquals(num, l.size());
|
||||||
|
|
Loading…
Reference in New Issue