0 0

Mybatis批处理报错10

代码如下:

 

List<VisitEntity> visits = new ArrayList<VisitEntity>();
VisitEntity uv = null;
for (int i = 0; i < 1000; i++) {
	uv = new VisitEntity();
	uv.setPage("http://www.site.com/");
	uv.setPageName("首页");
	uv.setReferer("http://www.site.com?wd=关键字");
	uv.setRefererDomain("http://www.baidu.com");
	uv.setSearchEngine("baidu");
	uv.setSearchWord("官网");
	uv.setSessionId("asadf232asdf22");
	uv.setTime(new java.util.Date());
	uv.setTrafficType("search");
	
	visits.add(uv);
}

SqlSessionFactory factory = MybatisUtil.getSqlSessionFactory();
SqlSession sqlSession = factory.openSession(ExecutorType.BATCH, false);
UserVisitMapper mapper = sqlSession.getMapper(UserVisitMapper.class);

//批量插入
long start = System.currentTimeMillis();

try {
	for (VisitEntity t : visits) {
		mapper.insert(t);
	}
	sqlSession.commit();
} catch (SQLException e) {
	e.printStackTrace();
}

long end = System.currentTimeMillis();
System.out.println("批量插入共花费时间" + (end-start) + "ms");

 

生成SqlSession,如果用默认的SimpleExecutor一切正常,换做BatchExecutor就会报下面的错误:

 

 

xception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error committing transaction.  Cause: java.lang.ArrayIndexOutOfBoundsException
### Cause: java.lang.ArrayIndexOutOfBoundsException
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:146)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:138)
	at com.cssweb.analytics.persistence.ServiceTest.main(ServiceTest.java:151)
Caused by: java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at oracle.jdbc.driver.T4CRowidAccessor.unmarshalOneRow(T4CRowidAccessor.java:202)
	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:610)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
	at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10622)
	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:597)
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:67)
	at $Proxy2.executeBatch(Unknown Source)
	at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:81)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:97)
	at org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:92)
	at org.apache.ibatis.executor.BaseExecutor.commit(BaseExecutor.java:172)
	at org.apache.ibatis.executor.CachingExecutor.commit(CachingExecutor.java:80)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:143)
	... 2 more

 

错误发生在下面这行:

 

 

at org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:81)

 

不知道这里面具体做了些什么事情,导致数组越界?

 

2012年8月10日 16:52
目前还没有答案

相关推荐

Global site tag (gtag.js) - Google Analytics