Skip to content

Use of parameterType attribute in select statement #102

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

Closed
sebdavid opened this issue Nov 21, 2013 · 3 comments
Closed

Use of parameterType attribute in select statement #102

sebdavid opened this issue Nov 21, 2013 · 3 comments

Comments

@sebdavid
Copy link

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 :

<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.

@emacarron
Copy link
Member

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.

@sebdavid
Copy link
Author

Thank you Eduardo.

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 ?

@emacarron
Copy link
Member

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).

See #98 for the full story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants