我在使用Postgres数据库通过映射xml文件&更新表中的内容时遇到错误在java中创建的服务类。
表结构,服务类方法,映射xml文件&测试代码如下
表:
CREATE TABLE "Itinerary"
(
"ItineraryID" serial NOT NULL,
"CustomerID" character varying(10) NOT NULL,
"PropertyCode" character varying(10) NOT NULL,
"ResvID" integer,
"ProfileID" integer NOT NULL,
"Summary" character varying(140),
"Description" text,
"CreatedBy" character varying(50),
"CreatedOn" timestamp without time zone,
"UpdatedBy" character varying(50),
"UpdatedOn" timestamp without time zone,
CONSTRAINT pk_itinerary PRIMARY KEY ("ItineraryID")
)
映射xml文件:更新操作
<update id="updateSelective" parameterClass="com.ginfo.data.itinerary.ItineraryData">
UPDATE "Itinerary" it
<dynamic prepend="SET">
<isNotNull prepend="," property="customerID">
"CustomerID" = #customerID:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="propertyCode">
"PropertyCode" = #propertyCode:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="resvID">
"ResvID" = #resvID:INTEGER#
</isNotNull>
<isNotNull prepend="," property="profileID">
"ProfileID" = #profileID:INTEGER#
</isNotNull>
<isNotNull prepend="," property="summary">
"Summary" = #summary:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="description">
"Description" = #description:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="updatedBy">
"UpdatedBy" = "#updatedBy:VARCHAR#
</isNotNull>
<isNotNull prepend="," property="updatedOn">
"UpdatedOn" = now()
</isNotNull>
</dynamic>
<include refid="Itinerary.where_PrimaryKey_Clause" />
</update>
服务类:
public ItineraryData save( ItineraryData itinerary ) throws Exception
{
Integer itineraryID = null;
if( itinerary != null )
{
try {
itineraryID = itinerary.getItineraryID();
if(itineraryID == null) {
itineraryID = itineraryDAO.insert(itinerary);
itinerary.setItineraryID(itineraryID);
}
else{
itineraryDAO.updateSelective(itinerary);
}
}
}
测试代码:
ItineraryData tinerary = new ItineraryData();
itinerary.setItineraryID(23);
itinerary.setCustomerID("0064152669");
itinerary.setPropertyCode("BHS");
itinerary.setResvID(9748);
itinerary.setProfileID(4618);
itinerary.setSummary("Schedule Preparation");
itinerary.setDescription("Schedule Preparation Description");
itinerary.setUpdatedBy(TESTUSER);
ItineraryData itinerary2 = itineraryService.save(itinerary2);
assertTrue("Itinerary is saved", itinerary2!= null && itinerary2.getItineraryID() != null);
当我运行测试代码时,我得到以下堆栈跟踪
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in resources/iBatis/BaseSqlMap.xml.
--- The error occurred while executing update.
--- Check the UPDATE "Itinerary" it SET "CustomerID" = ? , "PropertyCode" = ? , "ResvID" = ? , "ProfileID" = ? , "Summary" = ? , "Description" = ? , "UpdatedBy" = "? WHERE it."ItineraryID"=? .
--- Check the SQL Statement (preparation failed).
--- Cause: java.lang.ArrayIndexOutOfBoundsException
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeUpdate(MappedStatement.java:110)
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$9.doInSqlMapClient(SqlMapClientTemplate.java:380)
at org.springframework.orm.ibatis.SqlMapClientTemplate$9.doInSqlMapClient(SqlMapClientTemplate.java:1)
at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:200)
... 44 more
如何让它发挥作用?