You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There seems to be a few issues indeed and I will try to fix them, but you should know that columnPrefix is not used in constructor auto-mapping.
Constructor auto-mapping is performed using constructor signature (i.e. the number and the types of arguments).
In your demo, for example, Bar's constructor takes two arguments String and Integer.
MyBatis checks the returned columns in the specified order and use the first two values if they can be converted to String and Integer respectively.
In other words, constructor auto-mapping relies on the column order of your query.
Personally, I recommend explicit mapping for constructor.
harawata
changed the title
Constructor auto mapping failed using @AutomapConstructor
Constructor auto mapping could fail when columnPrefix is specified in the parent resultMap
Mar 10, 2019
Both this issue and #1496 should be fixed in the latest 3.5.1-SNAPSHOT.
Let us know if you find any issue!
p.s.
Another issue I noticed is that the columns used for constructor auto-mapping are used again in applyAutomaticMappings().
This means that the values are set to the same properties twice (first via constructor, then via setter (or directly if it's 'final')).
There also is a corner case that causes unintentional mappings.
The failing test is here.
That’s a known issue @harawata. I thought we talked about it last time. I can’t remember if we had said it was necessary for that 2nd level mapping for some reason.
Thank you for the comment, @h3adache !
I must have missed the point and didn't realize the 'same property is set twice' part, then.
If it's known, that should be fine. :)
MyBatis version
3.5.0
Database vendor and version
H2
Test case or example project
contructor_mapping.zip
Steps to reproduce
Run FooMapperTest to find one object Foo with an immutable Bar from DB
Expected result
get a Foo with a Bar constructed by autoMapping with columnPrefix "b_"
Actual result
An exception thrown with message:
...JdbcSQLSyntaxErrorException: Column "b_B_STR" not found ...
The text was updated successfully, but these errors were encountered: