1

I am trying to insert 1000 records into a table(Oracle DB) using mybatis as a batch opertaion(using ExecutorType.Batch in sqlsessionTemplate & <foreach> tag in mapper xml).
While executing the mapper function to insert,if there is any error inbetween, it rollbacks completely, skipping the remaining batch insertion process.
Our requirement is to log the error for records whichever failing,and continue with the insertion of remaining records.
Is there any possibility/option available in mybatis-batch insert to achieve this.

Sample query used in mapper XML:

<insert id="addSampleBatch" parameterType='java.util.Map'>
   INSERT ALL
   <foreach collection="sampleList" item="vehicle">
   INTO
     vehicle
            (id,name) 
   VALUES
      (#{vehicle.id}, 
       #{vehicle.name} )
   </foreach>
   SELECT * FROM dual
</insert> 

myBatis version:3.2.8
mybatis-spring jar version:1.2.2

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • Have you tried catching the error, then logging, then throwing it back for the rollback? – gonzo Mar 10 '16 at 14:58
  • Sounds more like a database problem... "Can I write an insert that ignores all errors and tries to continue at all costs?" – Florian Schaetz Mar 10 '16 at 17:27
  • Personally, I think it's an interesting question, btw, but unlikely to have a simple solution, since "Batch, but do not treat it as batch on failure" seems to be quite complex. The most obvious answer would be to remove the whole "batch" part and do one transaction per item, but of course you will not want to do that because speed... – Florian Schaetz Mar 11 '16 at 06:32
  • you used the stackoverflow tag "spring-batch" did you try it with spring batch? after all it looks suitable for skip, see https://docs.spring.io/spring-batch/reference/html/configureStep.html#configuringSkip – Michael Pralow Mar 14 '16 at 10:35
  • May be you can look into this question http://stackoverflow.com/questions/36036623/performance-issue-while-inserting-2000-records-using-mybatis3-2-8-version – Lucky Mar 19 '16 at 17:42

0 Answers0