|
MyBatis ExecutorType.BATCH 报ORA-01000: 超出打开游标的最大数的解决
1、登陆以dba管理角色权限登陆oracle,修改oracle默认游标最大数。
查看当前打开的游标数目
select count(*) from v$open_cursor;
修改Oracle最大游标数
alter system set open_cursors=1000 scope=both;
2、修改代码
最快捷方式修改 ExecutorType.BATCH 处理方式:
修改前:
batchSession = sessionFactory.openSession(ExecutorType.BATCH, session.getConnection());
修改后(手动提交):
batchSession = sessionFactory.openSession(false);
PreparedStatement prest = session.getConnection().prepareStatement(
commitFetchFrameSql, ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
for (FetchFrame fetchFrame : foundFrames) {
prest.setInt(1, fetchFrame.getState().getIndex());
prest.setTimestamp(2, new Timestamp(fetchFrame
.getRetrieveTime().getTime()));
prest.setInt(3, fetchFrame.getActualSpecsvsId());
prest.setLong(4, fetchFrame.getId());
prest.addBatch();
}
int[] executeBatch = prest.executeBatch();
两者处理方式都行,但是从性能来看 第一种方式处理效率比第二种最快快了1倍。
不建议从根本上解决问题,这涉及修改源码。 目前这种情况碰到oracle才出现过,所以,应该oracle特性导致的。
原因:应该是打开的statement或者preperedment过多导致的。而mybatis的这种ExecutorType.BATCH 处理方式是以List的preperedment来处理的。
有人说因为session.close是回到连接池而没有关闭连接的,我怀疑这种说法,因为跟踪了源码应该与session.close是无关的。 |
|
|