When injecting SQL (using $) that affects column names, you should use remapResults="true" on your select-statement.
Niels -----Original Message----- From: loctorp [mailto:[email protected]] Sent: Tuesday, January 27, 2009 10:33 AM To: [email protected] Subject: odd behaviour with select, resultset and header hi there, I experienced something rather peculiar yesterday: My map: <select id="getDataspaceValue" parameterClass="java.util.Map" resultClass="java.lang.String"> select $columnName$ from DATASPACE_TBL where NAME="$dataspace$"; </select> I execute this query 2 times. First time o.k.: ...select EARLIESTSAMPLE from DATASPACE_TBL where NAME="PERFORMANCE"; ...Executing Statement: select EARLIESTSAMPLE from DATASPACE_TBL where NAME="PERFORMANCE"; ...Parameters: [] ...Types: [] ... DEBUG java.sql.ResultSet - {rset-100004} ResultSet ... DEBUG java.sql.ResultSet - {rset-100004} Header: [EARLIESTSAMPLE] ... DEBUG java.sql.ResultSet - {rset-100004} Result: [1232499262400] second time with different column name (I'm interested in another column value): ...Preparing Statement: select LATESTSAMPLE from DATASPACE_TBL where NAME="PERFORMANCE"; ... Executing Statement: select LATESTSAMPLE from DATASPACE_TBL where NAME="PERFORMANCE"; ... DEBUG java.sql.PreparedStatement - {pstm-100005} Parameters: [] ... DEBUG java.sql.PreparedStatement - {pstm-100005} Types: [] ... DEBUG java.sql.ResultSet - {rset-100006} ResultSet com.ibatis.common.jdbc.exception.NestedSQLException: --- The error occurred in esa/egos/darc/admin/service/dataaccess/mysql/dataspace_mapping.xml. --- The error occurred while applying a result map. --- Check the getDataspaceValue-AutoResultMap. --- Check the result mapping for the 'EARLIESTSAMPLE' property. --- Cause: java.sql.SQLException: Column 'EARLIESTSAMPLE' not found. ....... and so on obviously the column name is somehow memorized. Why is column 'EARLIESTSAMPLE' looked for? The query explicitly asks for columnvalue for 'LATESTSAMPLE'. There is no column 'EARLIESTSAMPLE' in the resultSet for this query... If I inverse the order of execution, the problem stays the same, but then 'LATESTSAMPLE' is not found anymore... The workaround for now is a simple alteration of the map: <select id="getDataspaceValue" parameterClass="java.util.Map" resultClass="java.lang.String"> select $columnName$ as _value from DATASPACE_TBL where NAME="$dataspace$"; </select> which works, but I cannot explain the problem in the first place. Maybe someone could bring light into this? Thanks, cheers Mike -- View this message in context: http://www.nabble.com/odd-behaviour-with-select%2C-resultset-and-header- tp21682197p21682197.html Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
