Hi to everybody. I'm new to this forum.
I need to update an array of integers in Postgres with Ibatis 2.3.4 (and
Spring). I want to execute the following query:
UPDATE data SET='{1,2}' WHERE dataid=10
The query is
<update id="updateQuery" parameterClass="java.util.Map">
UPDATE data
<dynamic prepend="SET arrayData =" >
<iterate property="arrayData" open="'{" close="}'"
conjunction=",">
#arrayData[]#
</iterate>
</dynamic>
WHERE dataid=#dataId#
</update>
The method realized
public void updateData(int dataId, MyData mydata) {
Map<String, Object> params = new HashMap<String, Object>();
List<Integer> arrayData = mydata.getIntegerArray();
params.put("dataId", dataId);
params.put("arrayData", arrayData);
this.getSqlMapClientTemplate().update("updateQuery", params);
}
Executing the query I get the following response (arrayData contains 2
values):
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred while applying a parameter map.
--- Check the updateData-InlineParameterMap.
--- Check the parameter mapping for the 'arrayData[1]' property.
--- Cause: org.postgresql.util.PSQLException: The column index is out of
range: 2, number of columns: 1 at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.jav2009-04-07
10:27:26,727 DEBUG [java.sql.Connection] - {conn-100043} Connection
2009-04-07 10:27:26,729 DEBUG [java.sql.Connection] - {conn-100043}
Preparing Statement: UPDATE data SET arrayData =
'{ ? , ? }' WHERE dataId=?
a:107)
at
com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.update(SqlMapExecutorDelegate.java:457)
at
com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.update(SqlMapSessionImpl.java:90)
at
org.springframework.orm.ibatis.SqlMapClientTemplate$10.doInSqlMapClient(SqlMapClientTemplate.java:413)
at
org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
... 43 more
Caused by: org.postgresql.util.PSQLException: Indice di colonna, 2, è
maggiore del numero di colonne 1.
at
org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:52)
at
org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(SimpleParameterList.java:113)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc2Statement.java:2108)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.setInt(AbstractJdbc2Statement.java:1151)
at
org.apache.commons.dbcp.DelegatingPreparedStatement.setInt(DelegatingPreparedStatement.java:117)
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 $Proxy9.setInt(Unknown Source)
at
com.ibatis.sqlmap.engine.type.IntegerTypeHandler.setParameter(IntegerTypeHandler.java:30)
at
com.ibatis.sqlmap.engine.type.UnknownTypeHandler.setParameter(UnknownTypeHandler.java:69)
at
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameter(ParameterMap.java:166)
at
com.ibatis.sqlmap.engine.mapping.parameter.ParameterMap.setParameters(ParameterMap.java:126)
at
com.ibatis.sqlmap.engine.execution.SqlExecutor.executeUpdate(SqlExecutor.java:78)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteUpdate(MappedStatement.java:216)
at
com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:94)
... 47 more
I've also tried the same query with this variant
public void updateData(int dataId, MyData mydata) {
Map<String, Object> params = new HashMap<String, Object>();
int[] arrayData = mydata.getIntArray();
params.put("dataId", dataId);
params.put("arrayData", arrayData);
this.getSqlMapClientTemplate().update("updateQuery", params);
}
With the same result. Could someone suggest me a solution?
--
View this message in context:
http://www.nabble.com/Update-Postgres-Array-with-IBatis-tp22924852p22924852.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.