posted by 빛그루터기 2012. 3. 28. 13:07

spring 과 ibatis에서 insert구분을 여러개  돌릴 경우 batch를 이용하는데 있다

ORA-01000: 최대 열기 커서 수를 초과 에러가 떠서 보니 insert 구문이 300개가 넘어버려서

에러나 나네요

그래서 구글신에게 물어본 결과 아래와 같이 하면 잘 돌아갑니다.

 

참조

http://stackoverflow.com/questions/2921840/ibatis-startbatch-only-works-with-sqlmapclients-own-start-and-commit-transact

 

 

public void insertEmpSalmst(final List<SalAllSalaryModel> salpaylist) throws DataAccessException {
  super.execute(new SqlMapClientCallback() {

public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
    try {     
     int count = 0, total = 0;
     executor.startBatch();
     for (SalAllSalaryModel model : salpaylist) {
       executor.insert("ibatis 쿼리", model);
      }      
      count++;
      if (count % DB_BATCH_SIZE== 0)  { 
            total += executor.executeBatch();
            executor.startBatch();        
      }
     }

 total += executor.executeBatch();
    } catch (RuntimeException e) {
     e.printStackTrace();
    }
    return null;   

  }
  });
 }