You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Bing Zou <xi...@gmail.com> on 2005/01/15 06:40:17 UTC

One Question about Result Mapping.

I have been using iBATiS for about a week, it is great. Thanks a lot
for your excellent work. Now I have one question about the result
mapping:

When the resultClass has overloaded methods, for example, setID(int
ID) and setID(String ID), it seems that iBATiS will use the first
setID() (say, setID(int ID)) method in the method list returned by
reflection API as the result mapping method. While if the result
column in the database is type varChar instead of int, I will get
result mapping Exception.

I tried to switch the order of the two setID() methods in the class
and it worked. iBATiS picked up the first one (setID(String) now) in
the method list from reflection now. But I don't think this is a
correct way to solve this problem. I am wondering whether there is
some other way to do that? Actually, while using reflection to get the
setXXX method list, can we use Class.getMethod(String name, Class...
parameterTypes) instead of the general getMethods()? (Maybe this will
have a little bit impact on performance though.)

Any though/help will be appreciated.
Have a nice weekend.
Xigua

Re: One Question about Result Mapping.

Posted by Larry Meadors <la...@gmail.com>.
...and I would even call it "setId" instead of "setID" for similar reasons.

Larry

On Sun, 16 Jan 2005 11:16:24 +0530, Vamsee Kanakala <va...@gmail.com> wrote:
> >Yeah, this is just a bad design.  I would seriously recommend that you
> >consider naming your methods explicitly.
> >
> +1. Clinton put it far better that I would have.

Re: One Question about Result Mapping.

Posted by Vamsee Kanakala <va...@gmail.com>.
Clinton Begin wrote:

>Yeah, this is just a bad design.  I would seriously recommend that you
>consider naming your methods explicitly.  
>
+1. Clinton put it far better that I would have.



Re: One Question about Result Mapping.

Posted by Clinton Begin <cl...@gmail.com>.
Yeah, this is just a bad design.  I would seriously recommend that you
consider naming your methods explicitly.  Overloading JavaBean
properties isn't worth the problems you'll have, not only with iBATIS,
but with many other bean frameworks.

Name the pure typed setID() normally.  For type conversions, name the
bean properties explicitly, like setIDString(); or more generic
setIDText().

Overloading should be reserved for behaviour methods.  State classes
should rarely (i.e. never): 1) have overloaded properties, 2)
implement interfaces that describe state, 3) use deep inheritance
hierarchies.

Keep your JavaBeans simple, clear, and explicit.

Cheers,
Clinton


On Sat, 15 Jan 2005 00:40:17 -0500, Bing Zou <xi...@gmail.com> wrote:
> I have been using iBATiS for about a week, it is great. Thanks a lot
> for your excellent work. Now I have one question about the result
> mapping:
> 
> When the resultClass has overloaded methods, for example, setID(int
> ID) and setID(String ID), it seems that iBATiS will use the first
> setID() (say, setID(int ID)) method in the method list returned by
> reflection API as the result mapping method. While if the result
> column in the database is type varChar instead of int, I will get
> result mapping Exception.
> 
> I tried to switch the order of the two setID() methods in the class
> and it worked. iBATiS picked up the first one (setID(String) now) in
> the method list from reflection now. But I don't think this is a
> correct way to solve this problem. I am wondering whether there is
> some other way to do that? Actually, while using reflection to get the
> setXXX method list, can we use Class.getMethod(String name, Class...
> parameterTypes) instead of the general getMethods()? (Maybe this will
> have a little bit impact on performance though.)
> 
> Any though/help will be appreciated.
> Have a nice weekend.
> Xigua
>