});
}
for (final Field f : fields) {
final DatabaseFieldDescriptor databaseFieldDescriptor = getDatabaseFieldDescriptor(f);
if (databaseFieldDescriptor != null) {
if (!f.isAccessible()) {
f.setAccessible(true);
}
Object value;
try {
value = getOptionalValue(f.get(obj));
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException("Could not read value of field " + f.getName(), e);
} catch (final IllegalAccessException e) {
throw new IllegalArgumentException("Could not read value of field " + f.getName(), e);
}
if (value != null) {
// here we need apply any value/type transformation before generating the
value = applyTransformer(f, databaseFieldDescriptor, value);
}
final int fieldPosition = databaseFieldDescriptor.getPosition();
if (fieldPosition > 0) {
if (resultPositionMap == null) {
resultPositionMap = new TreeMap<Integer, Object>();
}
resultPositionMap.put(fieldPosition, value);
} else {
DbTypeField dbField = null;
if (dbFields != null) {
// we have type information from database (field positions)
final String dbFieldName = Mapping.getDatabaseFieldName(f, databaseFieldDescriptor.getName());
dbField = dbFields.get(dbFieldName);
if (dbField == null) {
throw new IllegalArgumentException("Field " + f.getName() + " (" + dbFieldName
+ ") of class " + clazz.getSimpleName() + " could not be found in database type "