我尝试使用来自Camel Route的MyBatis InsertList Batch向表中插入数据列表。 批处理失败,异常为java.sql.BatchUpdateException:ORA-00933:SQL命令未正确结束(下面有更多详细信息)。
我能够在没有MyBatis API问题的情况下插入数据列表(参见帖子中的第6节),但是只有在从驼峰路由使用时才会失败。
查询很好(参考5.帖子中的客户端上的SQL查询),因为我能够从SQL客户端成功插入数据。我尝试了几个选项并进行了大量研究,但不确定问题是什么。
如果你能对这个问题有所了解,我很感激。
使用的技术:
Java版本" 1.7.0_55"
Apache Camel 2.13.1
MyBatis 3.2.7
Oracle 11g
我将同样的问题发布到Camel Users
以下是与该问题相关的详细信息:
1。骆驼路线:
from("timer:foo?period=10000")
.setHeader(Exchange.HTTP_METHOD, constant(HttpMethods.GET))
.setHeader(Exchange.HTTP_URI, constant(RestURLs.TRANSACTION_BIDS_UNQUALIFIED_URL))
.process(new CamelGETMessageProcessor())
.to("restlet:http://someaddress.com/app/cts/bids")
.unmarshal(jaxbDataFormat)
.process(new TransactionBidsProcessor()) .to("mybatis:insertTransactionBidDetail?statementType=InsertList&executorType=batch")
.end();
2。映射器查询:
<insert id="insertTransactionBidDetail" parameterType="com.isone.cts.rest.binding.cts.TransactionBidsResponse">
INSERT ALL
<foreach item="p" collection="transactionBids.transactionBid"
open="" close="" separator=")">
into TRANSACTION_BIDS_DATA_T
(message_request_id, transaction_source,
transaction_sink, transaction_user_ref,
gis_identifier, jess_etag_id)
values(#{messageRequestID,jdbcType=NUMERIC},
#{p.transactionSource,jdbcType=VARCHAR},
#{p.transactionSink,jdbcType=VARCHAR},
#{p.transactionUserRef,jdbcType=VARCHAR},
#{p.gisIdentifier,jdbcType=VARCHAR},
#{p.jessETagID,jdbcType=VARCHAR}
</foreach>
)SELECT * FROM dual
</insert>
<insert id="insertTransactionBidDetail" parameterType="com.isone.cts.rest.binding.cts.TransactionBidsResponse">
INSERT ALL
<foreach item="p" collection="transactionBids.transactionBid"
open="" close="" separator=")">
into TRANSACTION_BIDS_DATA_T
(message_request_id, transaction_source,
transaction_sink, transaction_user_ref,
gis_identifier, jess_etag_id)
values(#{messageRequestID,jdbcType=NUMERIC},
#{p.transactionSource,jdbcType=VARCHAR},
#{p.transactionSink,jdbcType=VARCHAR},
#{p.transactionUserRef,jdbcType=VARCHAR},
#{p.gisIdentifier,jdbcType=VARCHAR},
#{p.jessETagID,jdbcType=VARCHAR}
</foreach>
)SELECT * FROM dual
</insert>
3。 SQL日志
[Camel(camel-1)thread#0 - timer:// foo] DEBUG transactionBidsMapper.insertTransactionBidDetail - ==&gt;准备:将TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值INSERT ALL(?,?,?,?,?,?)放入TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(将TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)中的?,?,?,?,?,?)放入TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink, transaction_user_ref,gis_identifier,jess_etag_id)将值(?,?,?,?,?,?)放入TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)成TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(? ,?,?,?,?,? )TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)到TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?进入TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier)的TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)中的,?,?,?,?) ,jess_etag_id)将值((?,?,?,?,?,?)转换为TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)到TRANSACTION_BIDS_DATA_T(message_request_id) ,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)in到TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,? )TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,?,?,?,?,?)到TRANSACTION_BIDS_DATA_T(message_request_id,transaction_source,transaction_sink,transaction_user_ref,gis_identifier,jess_etag_id)值(?,? ,?,?,?,?)SELECT * FROM dual
[Camel(camel-1)thread#0 - timer:// foo] DEBUG transactionBidsMapper.insertTransactionBidDetail - ==&gt;参数:1406290673069(BigDecimal),NODEISONE0(String),NODENYISO0(String),USERREFGPKL44220(String),HASHMASHSMASH(String),SCA_PSE _1110RCA(String),1406290673069(BigDecimal),NODEISONE1(String),NODENYISO1(String),USERREFGPKL44221( String),HASHMASHSMASH(String),SCA_PSE _1111RCA(String),1406290673069(BigDecimal),NODEISONE2(String),NODENYISO2(String),USERREFGPKL44222(String),HASHMASHSMASH(String),SCA_PSE _1112RCA(String),1406290673069(BigDecimal), NODEISONE3(String),NODENYISO3(String),USERREFGPKL44223(String),HASHMASHSMASH(String),SCA_PSE _1113RCA(String),1406290673069(BigDecimal),NODEISONE4(String),NODENYISO4(String),USERREFGPKL44224(String),HASHMASHSMASH(String) ,SCA_PSE _1114RCA(String),1406290673069(BigDecimal),NODEISONE5(String),NODENYISO5(String),USERREFGPKL44225(String),HASHMASHSMASH(String),SCA_PSE _1115RCA(String),1406290673069(BigDecimal),NODEISONE6(String),NODENYISO6( String),USERREFGPKL44226(String),HASHMASHSMASH(String),SCA_PSE _1116RCA(Str) ing),1406290673069(BigDecimal),NODEISONE7(String),NODENYISO7(String),USERREFGPKL44227(String),HASHMASHSMASH(String),SCA_PSE _1117RCA(String),1406290673069(BigDecimal),NODEISONE8(String),NODENYISO8(String),USERREFGPKL44228 (String),HASHMASHSMASH(String),SCA_PSE _1118RCA(String),1406290673069(BigDecimal),NODEISONE9(String),NODENYISO9(String),USERREFGPKL44229(String),HASHMASHSMASH(String),SCA_PSE _1119RCA(String),1406290673069(BigDecimal) ,NODEISONE10(String),NODENYISO10(String),USERREFGPKL442210(String),HASHMASHSMASH(String),SCA_PSE _11110RCA(String),1406290673069(BigDecimal),NODEISONE11(String),NODENYISO11(String),USERREFGPKL442211(String),HASHMASHSMASH(String ),SCA_PSE _11111RCA(String),1406290673069(BigDecimal),NODEISONE12(String),NODENYISO12(String),USERREFGPKL442212(String),HASHMASHSMASH(String),SCA_PSE _11112RCA(String),1406290673069(BigDecimal),NODEISONE13(String),NODENYISO13 (String),USERREFGPKL442213(String),HASHMASHSMASH(String),SCA_PSE _11 113RCA(String),1406290673069(BigDecimal),NODEISONE14(String),NODENYISO14(String),USERREFGPKL442214(String),HASHMASHSMASH(String),SCA_PSE _11114RCA(String) [Camel(camel-1)thread#0 - timer:// foo] DEBUG org.apache.ibatis.transaction.jdbc.JdbcTransaction - 回滚JDBC连接
4。以下是抛出的异常。
[Camel(camel-1)thread#0 - timer:// foo] DEBUG org.apache.camel.processor.DefaultErrorHandler - 在ExchangeId上传递失败(MessageId:ID-sporeddy-51161-1406290670797-0-1 :ID-sporeddy-51161-1406290670797-0-2)。在传递尝试时:0捕获:org.apache.ibatis.exceptions.PersistenceException:
[Camel(camel-1)thread#0 - timer:// foo] INFO org.apache.camel.processor.interceptor.Tracer - ID-sporeddy-51161-1406290670797-0-2&gt;&gt;&gt; (route5)mybatis:// insertTransactionBidDetail?executorType = batch&amp; statementType = InsertList - &gt; OnException [PersistenceException]&lt;&lt;&lt;模式:InOnly,Headers:{CamelMyBatisResult = -2147482646,breadcrumbId = ID-sporeddy-51161-1406290670797-0-1,firedTime = Fri Jul 25 08:17:53 EDT 2014,CamelMyBatisStatementName = insertTransactionBidDetail},BodyType:com.isone。 cts.rest.binding.cts.TransactionBidsResponse,正文:com.isone.cts.rest.binding.cts.TransactionBidsResponse@137c799 [Camel(camel-1)thread#0 - timer:// foo] INFO org.apache.camel.processor.interceptor.Tracer - ID-sporeddy-51161-1406290670797-0-2&gt;&gt;&gt; OnException [PersistenceException] - &gt; com.isone.cts.camel.processor.CamelPersistenceProcessor@19af694&lt;&lt;&lt;模式:InOnly,Headers:{CamelMyBatisResult = -2147482646,breadcrumbId = ID-sporeddy-51161-1406290670797-0-1,firedTime = Fri Jul 25 08:17:53 EDT 2014,CamelMyBatisStatementName = insertTransactionBidDetail},BodyType:com.isone。 cts.rest.binding.cts.TransactionBidsResponse,正文:com.isone.cts.rest.binding.cts.TransactionBidsResponse@137c799 [Camel(camel-1)thread#0 - timer:// foo] DEBUG com.isone.cts.camel.processor.CamelPersistenceProcessor - CamelPersistenceProcessor中的消息com.isone.cts.rest.binding.cts.TransactionBidsResponse@137c799 [Camel(camel-1)thread#0 - timer:// foo] DEBUG com.isone.cts.camel.processor.CamelPersistenceProcessor - CamelPersistenceProcessor中的标题{CamelMyBatisResult = -2147482646,breadcrumbId = ID-sporeddy-51161-1406290670797-0 -1,firedTime = Fri Jul 25 08:17:53 EDT 2014,CamelMyBatisStatementName = insertTransactionBidDetail} [Camel(camel-1)thread#0 - timer:// foo] DEBUG com.isone.cts.camel.processor.CamelPersistenceProcessor - 异常捕获org.apache.ibatis.exceptions.PersistenceException:
[Camel(camel-1)thread#0 - timer:// foo] DEBUG com.isone.cts.camel.processor.CamelPersistenceProcessor - PersistenceException getResponseBody
5。客户端上的SQL查询
INSERT ALL INTO TRANSACTION_BIDS_DATA_T ( message_request_id, transaction_source, transaction_sink, transaction_user_ref, gis_identifier, jess_etag_id ) VALUES ( 1406037318681, &#39; NODEISONE14&#39 ;, &#39; NODENYISO0&#39 ;, &#39; USERREFGPKL44220&#39 ;, &#39; HASHMASHSMASH&#39 ;, &#39; SCA_PSE _1110RCA&#39; ) INTO TRANSACTION_BIDS_DATA_T ( message_request_id, transaction_source, transaction_sink, transaction_user_ref, gis_identifier, jess_etag_id ) VALUES ( 1406037318681, &#39; NODEISONE14&#39 ;, &#39; NODENYISO0&#39 ;, &#39; USERREFGPKL44220&#39 ;, &#39; HASHMASHSMASH&#39 ;, &#39; SCA_PSE _1110RCA&#39; ) INTO TRANSACTION_BIDS_DATA_T ( message_request_id, transaction_source, transaction_sink, transaction_user_ref, gis_identifier, jess_etag_id ) VALUES ( 1406037318681, &#39; NODEISONE14&#39 ;, &#39; NODENYISO0&#39 ;, &#39; USERREFGPKL44220&#39 ;, &#39; HASHMASHSMASH&#39 ;, &#39; SCA_PSE _1110RCA&#39; ) INTO TRANSACTION_BIDS_DATA_T ( message_request_id, transaction_source, transaction_sink, transaction_user_ref, gis_identifier, jess_etag_id ) VALUES ( 1406037318681, &#39; NODEISONE14&#39 ;, &#39; NODENYISO0&#39 ;, &#39; USERREFGPKL44220&#39 ;, &#39; HASHMASHSMASH&#39 ;, &#39; SCA_PSE _1110RCA&#39; ) SELECT * FROM dual
6.从MyBatis API 运行相同查询时工作正常
private static void insertTransactionBidsDetailComplex() {
SqlSession session = null;
try {
TransactionBidsResponse transactionBidsResponse = new TransactionBidsResponse();
TransactionBids transactionBids = new TransactionBids();
transactionBids.getTransactionBid().addAll(
TransactionBidsDataGenerator.buildTransactionBidList());
transactionBidsResponse.setTransactionBids(transactionBids);
transactionBidsResponse.setMessageRequestID(new BigInteger(String
.valueOf(System.currentTimeMillis())));
transactionBidsResponse.setHeader(buildHeader());
session = getSqlSessionFactory().openSession();
insert = session.insert(
"transactionBidsMapper.insertTransactionBidDetail",
transactionBidsResponse);
session.commit();
} catch (Exception e) {
e.printStackTrace();
session.rollback();
} finally {
// close session
session.close();
}
}
答案 0 :(得分:2)
The issue lies with the setting below in MyBatis Configuration file:
<setting name="useGeneratedKeys" value="false" />
在端到端的痛苦调试中,我注意到在第No:103行抛出异常:batchResult.setUpdateCounts(stmt.executeBatch());在BatchExecutor.java(myBatis 3.2.7 jar)中。由于在MyBatis配置中使用useGeneratedKeys的选项设置为true,此时发生的情况是: RETURNING ROWID INTO?被添加到查询的末尾,这引发了异常。
我将其更改为false并且有效。
注意,除非您确定每个查询都需要返回的ROWID,否则不要将useGeneratedKeys设置为true。您可以在映射器文件中设置useGeneratedKeys选项以获得更多控制,例如下面:
<insert id="insertSomething" useGeneratedKeys="true"
keyProperty="id">
<!-- Some Query -->
</insert>