mybatis / mybatis-3

MyBatis SQL mapper framework for Java
http://mybatis.github.io/mybatis-3/
Apache License 2.0
19.8k stars 12.86k forks source link

@ResultType and @Params annotations doesn't work as expected #928

Closed malinink closed 7 years ago

malinink commented 7 years ago

MyBatis version

3.4.2

Database vendor and version

PostgreSQL 9.5

Test case or example project

In the case of usage SOLID principles to write our code with mybatis configuration in annotations I have met strange problems with @Params and @ResultType annotations.

I have created project with 3 PR that demonstrates that issues. https://github.com/malinink/mybatis3-test (all tests passed)

On each usecasse I create PR. https://github.com/malinink/mybatis3-test/pulls

Steps to reproduce

  1. https://github.com/malinink/mybatis3-test/pull/1/files
  2. https://github.com/malinink/mybatis3-test/pull/2/files
  3. https://github.com/malinink/mybatis3-test/pull/3/files (fix 2 PR failed tests by using class)

Expected result

  1. I expect that if mapper interface method have annotations like @ResultType - that it will be used with priority. Now - mybatis try to instantiate interface object, and fails.
  2. I expect that if relation presents in @Params - that javaType and typeHandler will works, but now they don't

Actual result

Tests fails until I use class names in both: POJO entities and they mappers.

harawata commented 7 years ago
  1. I expect that if mapper interface method have annotations like @ResultType - that it will be used with priority. Now - mybatis try to instantiate interface object, and fails.

  2. I expect that if relation presents in @Params - that javaType and typeHandler will works, but now they don't

Both expectations are wrong 😔 Please read the documentation for their usage. http://www.mybatis.org/mybatis-3/java-api.html

Closing as it's not a bug.