0
私は、Oracle DBとApache mybatisを使用してWeblogic 12cで動作するJavaアプリケーションを持っています。私は次のことをやっているJavaからmybatisに値のリストを挿入する
<resultMap id="DataQualityCRUDPlainResultMap" type="de.vkd.niswrapper.model.persistence.DataQualityCRUD">
<id column="ID" property="id" jdbcType="DECIMAL" />
<result column="REGION" property="region" jdbcType="DECIMAL" />
<result column="ONB_NUM" property="onbNum" jdbcType="DECIMAL" />
<result column="ASB_NUM" property="asbNum" jdbcType="DECIMAL" />
<result column="FIBERNODES_TOTAL" property="fiberNodesTotal" jdbcType="DECIMAL" />
<result column="FIBERNODES_COUNT" property="fiberNodesCount" jdbcType="DECIMAL" />
<result column="FIBERROUTE_TOTAL_COUNT" property="fiberrouteTotalCount" jdbcType="DECIMAL" />
<result column="FIBERROUTE_LONGITUDE" property="fiberrouteLongitude" jdbcType="DECIMAL" />
<result column="FIBERROUTE_TOTAL_COUNT_USED" property="fiberrouteTotalCountUsed" jdbcType="DECIMAL" />
<result column="FIBERROUTE_LONGITUDE_USED" property="fiberrouteLongitudeUsed" jdbcType="DECIMAL" />
<result column="DT_CREATION" property="dtCreation" jdbcType="TIMESTAMP" />
</resultMap>
<sql id="cols">
${alias}ID,
${alias}REGION,
${alias}ONB_NUM,
${alias}ASB_NUM,
${alias}FIBERNODES_COUNT,
${alias}FIBERNODES_TOTAL,
${alias}FIBERROUTE_TOTAL_COUNT,
${alias}FIBERROUTE_LONGITUDE,
${alias}FIBERROUTE_TOTAL_COUNT_USED,
${alias}FIBERROUTE_LONGITUDE_USED,
${alias}DT_CREATION
</sql>
<insert id="insert" parameterType="de.vkd.niswrapper.model.persistence.DataQualityCRUD">
INSERT INTO NW_NIS_DATA_QUALITY (
<include refid="cols">
<property name="alias" value="" />
</include>
)
VALUES (
#{id},
#{region},
#{onbNum},
#{asbNum},
#{fiberNodesTotal},
#{fiberNodesCount},
#{fiberrouteTotalCount},
#{fiberrouteLongitude},
#{fiberrouteTotalCountUsed},
#{fiberrouteLongitudeUsed},
#{dtCreation, jdbcType=TIMESTAMP}
)
</insert>
:
for (final DataQuality aDQ : aDQList) {
DataQualityCRUD myDDQCrud = new DataQualityCRUD();
fillFields(aRegion, now, aDQ, myDDQCrud); dataQualityCRUDMapper.insert(myDDQCrud);
}
これが働いているが、それは最適ではない私は、このマッパーを使用しています単一の挿入のために
。
ループ内のinsert
を削除し、値リストのinsert
を実行したいとしました。私は次のようでしたこれを達成するための
:
<insert id="insertAll" parameterType="java.util.Map">
INSERT INTO NW_NIS_DATA_QUALITY (
<include refid="cols">
<property name="alias" value="" />
</include>
) VALUES
<foreach collection="list" item ="element" open = "(" separator="),(" close=")">
#{element.id},
#{element.region},
#{element.onbNum},
#{element.asbNum},
#{element.fiberNodesTotal},
#{element.fiberNodesCount},
#{element.fiberrouteTotalCount},
#{element.fiberrouteLongitude},
#{element.fiberrouteTotalCountUsed},
#{element.fiberrouteLongitudeUsed},
#{element.dtCreation, jdbcType=TIMESTAMP}
</foreach>
</insert>
を残念ながら、これは次のように例外を発生させる(およびIれる:
Map<String, Object> map = new HashMap<String, Object>();
for (final DataQuality aDQ : aDQList) {
DataQualityCRUD myDDQCrud = new DataQualityCRUD();
fillFields(aRegion, now, aDQ, myDDQCrud);
resultList.add(myDDQCrud);
}
map.put("list", resultList);
dataQualityCRUDMapper.insertAll(map);
次のように私は私のMapper
insertAll
仕様に追加しました理解していないです):
### Error updating database. Cause: java.sql.SQLSyntaxErrorException:
ORA-00933: SQL command not properly ended ### The error may involve
de.vkd.niswrapper.adapter.gis.mapping.DataQualityCRUDMapper.insertAll-
Inline ### The error occurred while setting parameters ### SQL: INSERT
INTO NW_NIS_DATA_QUALITY (ID, REGION, ONB_NUM, ASB_NUM, FIBERNODES_COUNT,
FIBERNODES_TOTAL, FIBERROUTE_TOTAL_COUNT,
FIBERROUTE_LONGITUDE, FIBERROUTE_TOTAL_COUNT_USED,
FIBERROUTE_LONGITUDE_USED, DT_CREATION)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?),
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
### Cause: java.sql.SQLSyntaxErrorException:
ORA-00933: SQL command not properly ended ; bad SQL grammar [];
nested exception is java.sql.SQLSyntaxErrorException: ORA-00933:
SQL command not properly ended
NT?