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
I'm working with mybatis-3.1.1, but it's the same behavior with 3.2.3.
In a basic select statement using a parameter of type User, it seems that the parameterType attribute is ignored. For instance, there is the following query :
<select id="myQuery" parameterType="User" resultMap="myResultMap">
SELECT *
FROM table
WHERE field1 = #{firstname}
AND field2 = #{lastname}
</select>
If I remove the attribute parameterType, or if I set another value than "User" ("Country" for example, which does not have the fields firstname and lastname), the query will still be executed, until the passed object parameter contains the fields "firstName" and "lastName", as it looks for getters.
However, the documentation say that parameterType is "The fully qualified class name or alias for the parameter that will be passed into this statement.". So I understand it as it will be used to look for the fields value. But it seems that not.
Is it the normal behavior ? When should the parameterType attribute be used ? I don't find it in the documentation.
The text was updated successfully, but these errors were encountered:
Hi Sébastien. That parameter is optional. It can be omitted, and, as you discovered, most of the times it can even be wrong and cause no problems.
Up to 3.2.3 the parameterType attribute is just ignored but in 3.2.4 it will be used (but still optional) so in case it is wrong MyBatis will fail. We will include this in the release notes.
Regarding the doc. It is indeed incomplete. I will add an statement pointing that it is optional.
So, in 3.2.4, there will just be an additionnal check between the passed parameter type and the expected one ? Or will the parameterType attribute be used for another purpose ?
In 3.2.4 we will move process to the startup to speed up execution. One of the things we can move is the TypeHandler calculation.
But, during startup we do not know about the actual parameter so we can only use the xml attribute (or the declared parameter if using a mapper interface). You can still omit the attribute and it will be calculated later (with a little overhead).
Hello,
I'm working with mybatis-3.1.1, but it's the same behavior with 3.2.3.
In a basic select statement using a parameter of type User, it seems that the parameterType attribute is ignored. For instance, there is the following query :
If I remove the attribute parameterType, or if I set another value than "User" ("Country" for example, which does not have the fields firstname and lastname), the query will still be executed, until the passed object parameter contains the fields "firstName" and "lastName", as it looks for getters.
However, the documentation say that parameterType is "The fully qualified class name or alias for the parameter that will be passed into this statement.". So I understand it as it will be used to look for the fields value. But it seems that not.
Is it the normal behavior ? When should the parameterType attribute be used ? I don't find it in the documentation.
The text was updated successfully, but these errors were encountered: