mirror of https://github.com/apache/cloudstack.git
Fix NPE on adding new columns in the tables (#12464)
* Fix NPE on adding new columns in the tables * Remove assert
This commit is contained in:
parent
8db7cab7ba
commit
6e5d78a8a7
|
|
@ -89,6 +89,7 @@ import net.sf.cglib.proxy.NoOp;
|
|||
import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Element;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* GenericDaoBase is a simple way to implement DAOs. It DOES NOT
|
||||
|
|
@ -2047,16 +2048,22 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
|
|||
|
||||
@DB()
|
||||
protected void setField(final Object entity, final ResultSet rs, ResultSetMetaData meta, final int index) throws SQLException {
|
||||
Attribute attr = _allColumns.get(new Pair<String, String>(meta.getTableName(index), meta.getColumnName(index)));
|
||||
String tableName = meta.getTableName(index);
|
||||
String columnName = meta.getColumnName(index);
|
||||
Attribute attr = _allColumns.get(new Pair<>(tableName, columnName));
|
||||
if (attr == null) {
|
||||
// work around for mysql bug to return original table name instead of view name in db view case
|
||||
Table tbl = entity.getClass().getSuperclass().getAnnotation(Table.class);
|
||||
if (tbl != null) {
|
||||
attr = _allColumns.get(new Pair<String, String>(tbl.name(), meta.getColumnLabel(index)));
|
||||
attr = _allColumns.get(new Pair<>(tbl.name(), meta.getColumnLabel(index)));
|
||||
}
|
||||
}
|
||||
assert (attr != null) : "How come I can't find " + meta.getCatalogName(index) + "." + meta.getColumnName(index);
|
||||
setField(entity, attr.field, rs, index);
|
||||
if(attr == null) {
|
||||
logger.warn(String.format("Failed to find attribute in the entity %s to map column %s.%s (%s)",
|
||||
ClassUtils.getUserClass(entity).getSimpleName(), tableName, columnName));
|
||||
} else {
|
||||
setField(entity, attr.field, rs, index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue