ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Chase" <jcha...@gmail.com>
Subject Re: <resultMap> problems with <property> mappings
Date Thu, 15 Feb 2007 13:49:56 GMT
My mistake - I was under the assumption that column names were optional and
would default to the name of the property specified.

i.e. I was thinking:

<result property="foo" />

was the same as:

<result property="foo" column="foo" />

After I re-read some docs, I realized I had just imagined it:).  "column" is
a required attribute, according to the docs.

The SQLMaps PDF, page 31, states that both the property and column
attributes of <result> are not optional.  However, my resultmaps currently
are NOT using the column attribute and no errors are being thrown (I would
think that the resultmap should be seen as invalid at start up).

If the docs say that "column" is required, should a configuration error be
thrown if column values aren't specified or should the docs be updated?

Jon



On 2/14/07, Nathan Maves <nathan.maves@gmail.com> wrote:
>
> Why are you not specifying the column name or index?
>
> On 2/12/07, Jonathan Chase <jchase3@gmail.com> wrote:
> >
> > I kind of figured out the problem and a solution.
> >
> > I had an abstract class (AbstractEntity) that my entity (Foo) extended.
> > A simplified version of the classes looks like:
> >
> > public abstract class AbstractEntity {
> >    private Date creationDate;
> >    // getters/setters
> > }
> >
> > public class Foo extends AbstractEntity {
> >    private Date sentOn;
> >    private String a;
> >    private String b;
> >    private String c;
> >    // getters/setters
> > }
> >
> > (I doubt the abstract class had anything to do with the problem, but I
> > didn't factor it out to test that so I left it in for completeness.)
> >
> > And I had the following resultmap defined:
> > <resultMap id="adsf" class="foo">
> >   <result property name="creationDate" />
> >   <result property name="a" />    <result property name="b" />    <result
> > property name="c" />
> > </resultMap>
> >
> > The above works just fine.
> >
> > However, once I did the following:
> >  <resultMap id="adsf" class="foo">
> >   <result property name="creationDate" />
> > *  <result property name="sentOn" column="creationDate" />*
> >   <result property name="a" />
> >   <result property name="b" />    <result property name="c" />
> > </resultMap>
> >
> > I was getting the problem I previously described (property "a" was being
> > set with the value of column "b", property "b" would be set with the value
> > of column "c", etc.).
> >
> > So it looks like this stems from using the same result column
> > ("creationDate") twice in the result mapping when not specifying column
> > names explicitly.
> >
> > Also note that by explicitly assigning columns in the <result>s worked
> > (like <result property name="a" column="a" />), but wasn't desirable b/c I
> > just avoiding the problem for the time being:).
> >
> > Any ideas on why this is happening?  It seems like there's an off by one
> > error happening somewhere in the ibatis code.  Is ibatis assuming that
> > columns from the result set will only be used once?
> >
> > It'd be nice (if it hasn't already been documented or reported) to
> > figure this one out to prevent others from having the same problem.
> >
> > Jon
> >
> >
> > On 2/11/07, Jonathan Chase <jchase3@gmail.com > wrote:
> > >
> > > I'm using a result map like the following:
> > >
> > >
> > > <resultMap id="fooResultMap" class="my.Foo" extends= "
> > > Abstract.abstractResultMap">
> > >
> > > <result property="a" />
> > >
> > > <result property="b"  />
> > >
> > > </resultMap>
> > >
> > > When I use the above, for some unexplainable reason, the values for
> > > "a" and "b" column values in the Foo class instance are off by one from the
> > > database.  That is, the Java bean's "a" property has the value that b should
> > > have.  If there were a "c" property as well, "b" would have "c"'s expected
> > > value.
> > >
> > > I can make things work correctly when I specify the columns explicitly
> > > like this:
> > >
> > > <result property="a" column="a" />
> > >
> > > <result property="b" column="b"  />
> > >
> > > What in the world could cause this?
> > >
> > > I'm using ibatis 2.3 beta, Mysql 5, Java 5.
> > >
> > > Thanks,
> > >
> > > Jon
> > >
> >
> >
>

Mime
View raw message