Bug when resultClass is a map in dynamic statement
--------------------------------------------------
Key: IBATIS-354
URL: http://issues.apache.org/jira/browse/IBATIS-354
Project: iBatis for Java
Issue Type: Bug
Components: SQL Maps
Affects Versions: 2.2.0, 2.1.7
Environment: SUN JDK 1.4.2_10
Tomcat 5.0.28
MySQL 5.x
Reporter: sam zheng
When I want to return a map(HashMap) to temply get a summary result,I catch a
bug.
I change my ibatis from 2.1.7 to 2.2.0,the bug is still there.
I debug it in 2.2.0 with src and found the code seems to reuse the
resultMappings though the allowRemapping is false.
-------->
public ResultMapping[] getResultMappings() {
if (allowRemapping) {
return (ResultMapping[]) remappableResultMappings.get();
} else {
return resultMappings;
}
}
So when I change my dynamic statement from DAY(summaryType=DAY) to
MONTH(summaryType=MONTH),the column 'c_day' is not exits now,and then in
ObjectTypeHandler class,the getResult method want to invoke
rs.getObject(columnName),execption throw.
--------->
public Object getResult(ResultSet rs, String columnName)
throws SQLException {
Object object = rs.getObject(columnName);
if (rs.wasNull()) {
return null;
} else {
return object;
}
}
Exception is :
------------------->
org.apache.jasper.JasperException: Failed to queryForList - id [summary],
parameterObject [{summaryFor=MEMBER, dateFrom=2006-9-06, summaryType=MONTH,
dateTo=2006-10-06}]. Cause:
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in com/tuanzi/persistence/sql/Summary.xml.
--- The error occurred while applying a result map.
--- Check the summary-AutoResultMap.
--- Check the result mapping for the 'c_day' property.
--- Cause: java.sql.SQLException: Column 'c_day' not found.
Caused by: java.sql.SQLException: Column 'c_day' not found.
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.tuanzi.presentation.base.AccessFilter.doFilterInternal(AccessFilter.java:64)
com.tuanzi.presentation.base.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:59)
com.tuanzi.presentation.base.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:44)
com.tuanzi.presentation.base.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:59)
My sqlmap config file is :
-------------------->
<select id="summary" resultClass="java.util.HashMap"
parameterClass="java.util.Map">
<dynamic>
<isEqual property="summaryType" compareValue="DAY">
SELECT c_year,c_month,c_day,
</isEqual>
<isEqual property="summaryType" compareValue="MONTH">
SELECT c_year,c_month,
</isEqual>
<isEqual property="summaryType" compareValue="YEAR">
SELECT c_year,
</isEqual>
</dynamic>
sum(c_member_num) as c_member_num,
sum(c_group_num) as c_group_num,
sum(c_tip_num) as c_tip_num,
sum(c_forwar_num) as c_forwar_num
FROM
(
SELECT
year(c_registertime) as c_year,
month(c_registertime) as c_month,
day(c_registertime) as c_day,
count(*) as c_member_num,
0 as c_group_num,
0 as c_tip_num,
0 as c_forwar_num
FROM t_memberinfo
GROUP BY c_year,c_month,c_day
) as t
<dynamic>
<isEqual property="summaryType" compareValue="DAY">
<![CDATA[
WHERE
(
c_year>year(#dateFrom#)
OR
c_year=year(#dateFrom#) AND c_month>month(#dateFrom#)
OR
c_year=year(#dateFrom#) AND c_month=month(#dateFrom#) AND
c_day>=day(#dateFrom#)
)
AND
(
c_year<year(#dateTo#)
OR
c_year=year(#dateTo#) AND c_month<month(#dateTo#)
OR
c_year=year(#dateTo#) AND c_month=month(#dateTo#) AND
c_day<=day(#dateTo#)
)
GROUP BY c_year,c_month,c_day
ORDER BY c_year,c_month,c_day
]]>
</isEqual>
<isEqual property="summaryType" compareValue="MONTH">
<![CDATA[
WHERE
(
c_year>year(#dateFrom#)
OR
c_year=year(#dateFrom#) AND c_month>=month(#dateFrom#)
)
AND
(
c_year<year(#dateTo#)
OR
c_year=year(#dateTo#) AND c_month<=month(#dateTo#)
)
GROUP BY c_year,c_month
ORDER BY c_year,c_month
]]>
</isEqual>
<isEqual property="summaryType" compareValue="YEAR">
<![CDATA[
WHERE
(
c_year>=year(#dateFrom#)
)
AND
(
c_year<=year(#dateTo#)
)
GROUP BY c_year
ORDER BY c_year
]]>
</isEqual>
</dynamic>
</select>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira