From c1b66519c1954b5c6ad131372246ecc951498f39 Mon Sep 17 00:00:00 2001 From: Alexander Kovtunenko Date: Tue, 12 Dec 2017 18:21:10 +0200 Subject: [PATCH] added protection from NPE --- .../norm/sqlmakers/StandardSqlMaker.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java index 6372268..26b6a46 100644 --- a/src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java +++ b/src/main/java/com/dieselpoint/norm/sqlmakers/StandardSqlMaker.java @@ -331,33 +331,33 @@ public void populateGeneratedKey(ResultSet generatedKeys, Object insertRow) { try { Property prop = pojoInfo.getGeneratedColumnProperty(); - boolean isInt = prop.dataType.isAssignableFrom(int.class); // int or long - - Object newKey; - - // if there is just one column, it's the generated key - // postgres returns multiple columns, though, so we have the fetch the value by name - int colCount = generatedKeys.getMetaData().getColumnCount(); - if (colCount == 1) { + if(prop != null) + { + boolean isInt = prop.dataType.isAssignableFrom(int.class); // int or long + Object newKey; + // if there is just one column, it's the generated key + // postgres returns multiple columns, though, so we have the fetch the value by name + int colCount = generatedKeys.getMetaData().getColumnCount(); + if (colCount == 1) { if (isInt) { newKey = generatedKeys.getInt(1); } else { newKey = generatedKeys.getLong(1); } - } else { + } else { // colcount > 1, must do by name if (isInt) { newKey = generatedKeys.getInt(prop.name); } else { newKey = generatedKeys.getLong(prop.name); } - } - - pojoInfo.putValue(insertRow, prop.name, newKey); + } - } catch (Throwable t) { + pojoInfo.putValue(insertRow, prop.name, newKey); + } + } catch (Throwable t) { throw new DbException(t); - } + } }