mybatis 3.4.4 use annotation @Result can not map custom Java generic that already define the class Type in return param

56 views
Skip to first unread message

喻奇

unread,
Mar 17, 2020, 12:47:11 AM3/17/20
to mybatis-user

1584418780129.jpg


just like pic show

,I have difine RecordInfo<T>  class , and i Return the RecordInfo<RiskInfo>  in queryRiskList function.but i use @Result(property = "content.appId", column = "app_id")  to map RiskInfo class Feild appId to database column app_id when I run  this function,I get this error "org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'appId' in 'class java.lang.Object'",  but I define the  type of content as RiskInfo in Function return params, why mybatis can not
 discern the RiskInfo class,how could I solve this error?

Guy Rouillier

unread,
Mar 17, 2020, 4:42:54 AM3/17/20
to mybati...@googlegroups.com
Why is your map mapping appId twice, once for appInfo.appId and again for content.appId?

To answer your question, this appears to be the classic problem of type erasure with generics:


--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/054182d4-dc96-4dbc-beeb-4f7a8e2ba020%40googlegroups.com.

喻奇

unread,
Mar 19, 2020, 3:41:37 AM3/19/20
to mybatis-user


在 2020年3月17日星期二 UTC+8下午4:42:54,Guy Rouillier写道:
Why is your map mapping appId twice, once for appInfo.appId and again for content.appId?

To answer your question, this appears to be the classic problem of type erasure with generics:


--
Guy Rouillier

On 3/17/2020 12:47:11 AM, "喻奇" <yich...@gmail.com> wrote:

1584418780129.jpg


just like pic show

,I have difine RecordInfo<T>  class , and i Return the RecordInfo<RiskInfo>  in queryRiskList function.but i use @Result(property = "content.appId", column = "app_id")  to map RiskInfo class Feild appId to database column app_id when I run  this function,I get this error "org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'appId' in 'class java.lang.Object'",  but I define the  type of content as RiskInfo in Function return params, why mybatis can not
 discern the RiskInfo class,how could I solve this error?

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybati...@googlegroups.com.
hi,thanks for your reply,mapping appId twice is not question that i ask,my question neither is java Type Erasure ,i wonder  “use annotation @Result can not map custom Java generic that already define the class Type in return param

Guy Rouillier

unread,
Mar 20, 2020, 1:11:51 AM3/20/20
to mybati...@googlegroups.com
>> my question neither is java Type Erasure ,i wonder  “use annotation @Result can not map custom Java generic that already define the class Type in return param

Well, that may not be the question you asked, but appears to be the situation you face:

"org.apache.ibatis.reflection.ReflectionException: There is no setter for property named 'appId' in 'class java.lang.Object'"

If you are able to post a *simple* example, I'm willing to take a look, since we are on coronavirus isolation.  From what you have provided, I cannot see how "content" is defined.

--
Guy Rouillier
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/ec371a86-5f03-48b6-8c89-456c62239f55%40googlegroups.com.

喻奇

unread,
Mar 25, 2020, 11:58:31 PM3/25/20
to mybatis-user

1585194816723.jpg

as the pic show,content is defined as  Java generic, but at the function return param "RecordInfo<RiskInfo>" ,I already define java generic T as  "RiskInfo.class",  so why "use annotation @Result can not map custom Java generic that already define the class Type in return param




在 2020年3月20日星期五 UTC+8下午1:11:51,Guy Rouillier写道:
Reply all
Reply to author
Forward
0 new messages