-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
avoid unexpected automapping #895
Conversation
…ame name as another column
Could you provide a test case? |
@harawata Hi, I added a test case to the existed auto mapping test suite |
Thank you, @dulong ! =D |
@harawata , Is this enhancement or bug ? |
A bug, I would say. |
Do not need a warning log in this case ? |
@@ -477,7 +477,7 @@ private Object getPropertyMappingValue(ResultSet rs, MetaObject metaResultObject | |||
} | |||
} | |||
final String property = metaObject.findProperty(propertyName, configuration.isMapUnderscoreToCamelCase()); | |||
if (property != null && metaObject.hasSetter(property)) { | |||
if (property != null && metaObject.hasSetter(property) && !resultMap.getMappedProperties().contains(property)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should not use &&
condition in this case.
Because...
If resultMap.getMappedProperties().contains(property)
is true
, execute following code.
configuration.getAutoMappingUnknownColumnBehavior()
.doAction(mappedStatement, columnName, (property != null) ? property : propertyName, null);
In this case, i think it is already mapped property rather than not unknown column.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not fully understand the expected behavior of autoMappingUnknownColumnBehavior.
Feel free to commit the necessary changes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not fully understand the expected behavior of autoMappingUnknownColumnBehavior.
See #585.
I will improve a contributing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK..I have to admit that I am a little bit confused 😆
Please let me clarify.
When running the contributed test case (AutomappingTest.shouldGetAUserWhithPhoneNumber()), four columns (id, name, phone and phone_number) are returned from the query and only three of them are mapped.
- 'phone_number' is explicitly mapped
- 'id' and 'name' are auto-mapped
I thought that the unmapped column 'phone' is an unknown column, but it actually isn't, is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @harawata
In My opinion, the phone
is valid column name as auto-mapping (if does not use explicit mapping...), it skip because it has been mapped by explicit mapping already. Hence i think phone
is not unknown column.
I think we should consider to apply a mechanism that notify duplicate mapping for same property (like same as autoMappingUnknownColumnBehavior).
for example:
NONE
: skip auto-mappingWARNING
: skip auto-mapping and output warning log that notify duplicate mapping for same propertyFAILING
: throw exception that that notify duplicate mapping for same property
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hence i think phone is not unknown column.
Okay, I have no strong opinion about this.
I think we should consider to apply a mechanism that notify duplicate mapping for same property (like same as autoMappingUnknownColumnBehavior).
The duplicate mapping situation like this would be rare.
And this unknown column detection can be inaccurate [1] anyway, so let's consider when someone desperately wants it ;)
[1] There will be false-positives with a nested result map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's consider when someone desperately wants it ;)
Okay :)
Hi @kazuki43zoo , thanks for the improvement, i appreciated that 👍 |
avoid unexpected automapping when a explicit mapped proerty has the same name as another column