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 <[EMAIL PROTECTED]> 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