Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
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
Expand Down Expand Up @@ -2047,16 +2048,23 @@ public boolean unremove(ID id) {

@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);
assert (attr != null) : "How come I can't find " + tableName + "." + columnName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the assert

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
Expand Down
Loading