当PgSQL的表 主键不是在表的第一个栏位的时候 getGeneratedKeys方法报错的问题
导致 Model.java
需要做出下列修改
/**
* Get id after save method.
*/
private void getGeneratedKey(PreparedStatement pst, Table table, Config config) throws SQLException {
String[] pKeys = table.getPrimaryKey();
ResultSet rs = pst.getGeneratedKeys();
for (String pKey : pKeys) {
if (get(pKey) == null || config.dialect.isOracle()) {
if (rs.next()) {
Class colType = table.getColumnType(pKey);
//由于Postgresql的getGeneratedKeys返回的是所有的数据所以这里不能用index的方式获取 应该用主键名称获取
if (colType == Integer.class || colType == int.class)
set(pKey, rs.getInt(1)); 改为 set(pKey, rs.getInt(pKey));
else if (colType == Long.class || colType == long.class)
set(pKey, rs.getLong(1)); 改为 set(pKey, rs.getLong(pKey));
else
set(pKey, rs.getObject(1)); 改为 set(pKey, rs.getObject(pKey)); // It returns Long object for int colType
}
}
}
rs.close();
}