Skip to content
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

Add new option for specify the behavior when detects an unknown column of automatic mapping target #585

Conversation

kazuki43zoo
Copy link
Member

I added a new option for specify the behavior when detects an unknown column (or unknown property type) of automatic mapping target.

Options are as follow:

  • NONE : Do nothing (Default) -> Same with current implementation
  • WARNING : Output warning log with detail
  • FAILING : Fail mapping (throw SqlSessionException with detail)

I think this option is useful for detects a type mistake during development.

What do you think ?

@emacarron
Copy link
Member

Hi @kazuki43zoo. Looks good and useful. The only comment I would make is that I would not expect to find code in an enumeration (thought it may be a matter of taste indeed).

@kazuki43zoo
Copy link
Member Author

Hi @emacarron , thanks for comment!
I often use this technique to switch a processing per enum value. But i can change to other implementation. Should it change ?

@emacarron
Copy link
Member

I would appreciate it. I would say it will fit better with current code style. Thanks in advance and thank you!

@kazuki43zoo
Copy link
Member Author

I've improved message via 09cb34a.

emacarron added a commit that referenced this pull request Feb 26, 2016
…knownColumnBehavior

Add new option for specify the behavior when detects an unknown column of automatic mapping target
@emacarron emacarron merged commit 2f390a5 into mybatis:master Feb 26, 2016
@kazuki43zoo kazuki43zoo deleted the add-new-option-AutoMappingUnknownColumnBehavior branch February 26, 2016 14:34
@kazuki43zoo
Copy link
Member Author

Thanks for merging!! I want to backport to 3.3.x line. Is OK?

@kazuki43zoo
Copy link
Member Author

And i will fix docs at later.

@kazuki43zoo
Copy link
Member Author

@emacarron plz set milestone !!

kazuki43zoo added a commit to kazuki43zoo/mybatis-3 that referenced this pull request Feb 26, 2016
@emacarron emacarron added the enhancement Improve a feature or add a new feature label Feb 26, 2016
@emacarron emacarron added this to the 3.4.0 milestone Feb 26, 2016
@emacarron emacarron self-assigned this Feb 26, 2016
@emacarron
Copy link
Member

done! :)

2016-02-26 17:00 GMT+01:00 Kazuki Shimizu notifications@github.com:

@emacarron https://github.com/emacarron plz set milestone !!


Reply to this email directly or view it on GitHub
#585 (comment).

emacarron added a commit that referenced this pull request Feb 26, 2016
@kazuki43zoo
Copy link
Member Author

@jarvan4dev Could you provide a reproduce project that can be run on GitHub ?

@kazuki43zoo
Copy link
Member Author

@jarvan4dev Not need to provide your real project. I need a minimum reproduce project.

@kazuki43zoo
Copy link
Member Author

Please check query that do mapping using needResultMap.

@kazuki43zoo
Copy link
Member Author

Sorry, you can forget my above comment.

@harawata
Copy link
Member

There will be false-positives when using a nested result map (a result map with collection or association).
It's relatively easy to reproduce it. Try enabling autoMappingUnknownColumnBehavior in a test like this for example.

If there is a simple fix, that would be great.
Otherwise, we should keep it as a known limitation rather than messing up DefaultResultSetHandler.

@kazuki43zoo
Copy link
Member Author

Hi @harawata,
I agree with a known limitation when using a nested result map on collection or association. However in this case, nested result map seems not use. I don't know why become this behavior. Could you explain a reason ?

@kazuki43zoo
Copy link
Member Author

@jarvan4dev
Which mode does autoMappingBehavior use? NONE or PARTIAL(default) or FULL ?

See http://www.mybatis.org/mybatis-3/configuration.html#settings.

@harawata
Copy link
Member

@jarvan4dev ,
I meant it was expected judging from the implementation.
This feature may be useful to detect some simple mistakes during development (as mentioned in the initial comment of this PR), but it could be inaccurate with complex use cases.

@kazuki43zoo ,
In @jarvan4dev 's example, needDetailResultMap contains <association /> and <collection />. They are nested result maps.

  • When processing the parent result map, columns that will be mapped to the nested association or collection (e.g. issuer_id, issuer_avatar, taker_id, etc.) are detected as unmapped.
  • When processing the nested association result map, columns like need_id, title, taker_id are detected as unmapped.
  • When processing the nested collection result map, columns like need_id, title, issuer_id are detected as unmapped.

@kazuki43zoo
Copy link
Member Author

@harawata Thanks for your answer !
Is behavior depends on autoMappingBehavior mode (or autoMapping attribute on collection or association ?

@harawata
Copy link
Member

Is behavior depends on autoMappingBehavior mode (or autoMapping attribute on collection or association ?

Yes. If autoMappingBehavior is set to PARTIAL, for example, auto-mapping is not performed on a result map containing association or collection.

@kazuki43zoo
Copy link
Member Author

kazuki43zoo commented Mar 22, 2017

@jarvan4dev Thanks for reply !
For details about this behavior see @harawata's comment. (#585 (comment)).

If you want to use the auto-mapping for nested object(result map), this feature cannot report unknown column accurately. This is a known limitation.

I will consider to apply this limitation to the reference documentation.

@harawata
Copy link
Member

if autoMappingBehavior=FULL and autoMappingUnknownColumnBehavior =WARNING there will be some warnings which are false-positive

That's correct.

to avoid this, we should set autoMappingBehavior=PARTIAL

If you don't need auto-mapping on nested result maps, then using PARTIAL would be a good solution.

pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
…ppingUnknownColumnBehavior

Add new option for specify the behavior when detects an unknown column of automatic mapping target
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants