-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix if parameterType is simple type, then throws java.lang.NoSuchMeth… #834
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
Conversation
…odException: xxx.<init>()
Hi @abel533, Thanks for contributing !! |
Hi @abel533 , Probably you can resolve this issue using single parameter instead of composite parameter(such as <resultMap id="userRoleMapSelect" extends="userMap" type="tk.mybatis.simple.model.SysUser">
<association property="role"
select="selectRoleById"
javaType="tk.mybatis.simple.model.SysRole"
- column="{id=role_id}"/>
+ column="role_id"/> |
Hi @abel533, I think your fix is not appropriate because the As alternative, I will propose to fix at the private Object instantiateParameterObject(Class<?> parameterType) {
if (parameterType == null) {
return new HashMap<Object, Object>();
+ } else if (SimpleTypeRegistry.isSimpleType(parameterType)
+ || typeHandlerRegistry.hasTypeHandler(parameterType)) {
+ return new HashMap<Object, Object>();
} else if (ParamMap.class.equals(parameterType)) {
return new HashMap<Object, Object>(); // issue #649
} else {
return objectFactory.create(parameterType);
}
} @emacarron @harawata, What do you think about my opinion ? I want to hear everyone opinion. |
In that example, I encourage users to omit parameterType.
So, it is better/safer to omit parameterType. |
@harawata , thanks you for replying !!
Ok, i agree with your opinion. In this case ... , we should choose from following solutions.
Probably, if nested query has been implemented on @Results(
@Result(property = "role", one = @One(select = "selectRoleById"), column = "role_id")
)
@Select("select * sys_user where id = #{id}")
SysUser selectUser(Long id);
@Select("select * from sys_role where id = #{id}")
SysRole selectRoleById(Long id); |
As mentioned here: https://github.com/mybatis/mybatis-3/blob/master/src/test/java/org/apache/ibatis/submitted/complex_column/Person.xml#L45 In that example, because it using RAW, so the paremter is a |
@wuwen5 , In that example, Regarding the difference between raw and dynamic statement, please see Eduardo's explanation here. |
Thank you! @harawata. |
@kazuki43zoo I think your fix is appropriate. You can fix it in your way. |
Fix if parameterType is simple type, then throws java.lang.NoSuchMethodException: xxx.();
Recreate the problem, in nested query:
the selectRoleById also can be use in annotation: