ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Savitsky <ASavit...@cihi.ca>
Subject RE: Trying to use HashMap as a param object for an UPDATE - getting an exception
Date Wed, 10 Dec 2008 14:22:17 GMT
No, it wasn't this, when I removed the extra parameters, the result was the same. I even went
into the iBATIS initialization code with a debugger (something I always end up doing for such
poorly documented frameworks), and discovered that, when there's a parameter map specified,
the SQL is not even parsed for the ## parameters (the parsing is supposed to replace them
with '?'s), and sent to DB as is - most likely a bug. Ended up using the implicit maps, like
this:
 
<update id="updateSector" parameterClass="java.util.HashMap">
UPDATE SECTOR SET SECTOR_DESC = #description:VARCHAR# WHERE SECTOR_ID = #id:NUMERIC#
</update>

This way, the SQL gets parsed, and all ##s are properly replaced with '?'s
________________________________

From: luc [mailto:luc.mdk@gmail.com] 
Sent: Tuesday, December 09, 2008 8:57 PM
To: user-java@ibatis.apache.org
Subject: Re: Trying to use HashMap as a param object for an UPDATE - getting an exception


I think your update sql statement has 2 questionmarks,but it try to set 4 parameters to fill
those.
You can set the log level to DEBUG for javax.sql,then may be find more informations.


2008/12/10 Alex Savitsky <ASavitsky@cihi.ca>


	Hi,
	
	I'm trying to execute an update, with a HashMap for parameter (there's no business object
to pass). The mapping file is as follows (iBATIS v.2.3.0.677)
	
	<?xml version="1.0" encoding="UTF-8" ?>
	<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd">
	<sqlMap namespace="Sector">
	<resultMap class="java.util.HashMap" id="sector">
	       <result property="id" column="SECTOR_ID" javaType="java.lang.Integer" />
	       <result property="code" column="SECTOR_CD" />
	       <result property="description" column="SECTOR_DESC" />
	       <result property="fiscalYear" column="FISCAL_YR" javaType="java.lang.Integer" />
	</resultMap>
	<parameterMap class="java.util.HashMap" id="sector">
	       <parameter property="id" jdbcType="NUMERIC" />
	       <parameter property="code" jdbcType="VARCHAR" />
	       <parameter property="description" jdbcType="VARCHAR" />
	       <parameter property="fiscalYear" jdbcType="NUMERIC" />
	</parameterMap>
	<select id="getSectorList" resultMap="sector" parameterMap="sector">
	       SELECT * FROM SECTOR WHERE FISCAL_YR = #fiscalYear#
	       <isNotEmpty property="code">AND SECTOR_CD LIKE #code#||'%'</isNotEmpty>
	       <isNotEmpty property="description">AND SECTOR_DESC LIKE #description#||'%'</isNotEmpty>
	</select>
	<update id="updateSector" parameterMap="sector">
	       UPDATE SECTOR SET SECTOR_DESC = #description# WHERE SECTOR_ID = #id#
	</update>
	</sqlMap>
	
	Both parameters and results are Maps, and the select works when I pass it a parameter map,
whether it has all the properties, or not. Update, however, fails:
	
	Map s1 = new HashMap();
	s1.put("code", "001");
	s1.put("description", "Region Transaction upd");
	s1.put("fiscalYear", "2005");
	s1.put("id", "1501");
	client.update("updateSector", s1);
	
	com.ibatis.common.jdbc.exception.NestedSQLException:
	--- The error occurred in ca/cihi/cmdb/model/Sector.xml.
	--- The error occurred while applying a parameter map.
	--- Check the Sector.sector.
	--- Check the parameter mapping for the 'id' property.
	--- Cause: java.sql.SQLException: Invalid column index
	       at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:91)
	       at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:505)
	       at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl.java:90)
	       at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.update(SqlMapClientImpl.java:67)
	       at ca.cihi.cmdb.service.MaintenanceService.update(MaintenanceService.java:52)
	       ... 29 more
	Caused by: java.sql.SQLException: Invalid column index
	       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
	       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
	       at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227)
	       at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4754)
	       at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:4717)
	       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	       at java.lang.reflect.Method.invoke(Method.java:585)
	       at com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke(PreparedStatementLogProxy.java:70)
	       at $Proxy2.setString(Unknown Source)
	       at com.ibatis.sqlmap.engine.type.StringTypeHandler.setParameter(StringTypeHandler.java:30)
	       at com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter(UnknownTypeHandler.java:69)
	       at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameter(BasicParameterMap.java:165)
	       at com.ibatis.sqlmap.engine.mapping.parameter.BasicParameterMap.setParameters(BasicParameterMap.java:125)
	       at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:79)
	       at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.sqlExecuteUpdate(GeneralStatement.java:200)
	       at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeUpdate(GeneralStatement.java:78)
	       ... 33 more
	
	Am I doing something wrong?
	
	Thanks,
	
	Alex



Mime
View raw message