google-code-export / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Object is not created when all constructor arguments are 'null'. #798

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What version of the MyBatis are you using?
3.2.0

Please describe the problem.  Unit tests are best!
When <ResultMap> contains a <contstructor> element, and if all of the 
constructor arguments to be injected by MyBatis are 'null', such row is 
silently ignored.
When I debugged the test,  inside the method with signature 
'org.apache.ibatis.executor.resultset.FastResultSetHandler#createParameterizedRe
sultObject',
it ignores such cases and just returns null, instead of invoking 
objectFactory.create(resultType, constructorArgTypes, constructorArgs).

Someone already posted the same issue on mybatis-user 
group.(https://groups.google.com/forum/#!topic/mybatis-user/nAR5lSqywDw)

What is the expected output? What do you see instead?
When <ResultMap> contains a <contstructor> element, and if all of the 
constructor arguments to be injected by MyBatis are 'null', such row is 
silently ignored.
The expected outcome is to invoke constructor with null parameters.

Can you provide stack trace, logs, error messages that are displayed?
I attached the testcode along with the suggested code patch, which simply get 
rids of the 'foundValues' variable.
(I haven't thought of consequences of this change in other circumstances.)

Please provide any additional information below.

Original issue reported on code.google.com by daniel0...@gmail.com on 21 Mar 2013 at 10:58

Attachments:

GoogleCodeExporter commented 9 years ago
there is a setting called "callSettersOnNulls", default value is false. you can 
set it in xml file
<configuration>
    <settings>
        <setting name="callSettersOnNulls" value="true" />
......
</settings>
</configuration>

if you enable the setting, ibatis may call setter on primitive types such as 
int, boolean to set a null value, that will throw out a error, please do some 
regression test after you enable this.
in 3.2.2 snapshot, the issue is fixed.

Original comment by xiao...@gmail.com on 22 Mar 2013 at 2:53

GoogleCodeExporter commented 9 years ago
Yep. I am afraid this combination is not supported. 

If there is a not default constructor mybatis considers that at least one 
constructor parameter must not be null. Otherwise the object is discarded.

This is intentional (for simplicity) not a bug. But will keep this as a feature 
request.

Original comment by eduardo.macarron on 25 Mar 2013 at 8:58