Announcement Announcement Module
Collapse
No announcement yet.
Newbie: Using Itemwriter to update record if insert fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie: Using Itemwriter to update record if insert fails

    Hi guys,

    I am new to Spring Batch. I have a FlatFileItemReader and then write these files to my database using JDBCBatchItemWriter. I will paste the code of the itermwriter. Currently the value of the sql inserts. There are primary keys on my table, so if the insert fails because of data integrity, I would like to update the record instead. I have read up a bit and came across skippable exceptions and composite writers, but can't really see how to get the concepts together. What is the best way to do this? Examples would also help as I am very new to Spring Batch concepts.

    <beans:bean id="ItemWriter.CardTransactionDataJob" class="org.springframework.batch.item.database.Jdb cBatchItemWriter">
    <beansroperty name="assertUpdates" value="false"/>
    <beansroperty name="itemSqlParameterSourceProvider">
    <beans:bean name="sqlParameterSourceProvider" id="sqlParameterSourceProvider"
    class="org.springframework.batch.item.database.Bea nPropertyItemSqlParameterSourceProvider"/>
    </beansroperty>
    <beansroperty name="sql" value="insert into CARD_TRN (member_id,member_item_id,card_account_id,display_ name,item_account_id)
    values(:memberId, :memberItemId, :cardAccountId, :displayName, :itemAccountId)"/>
    <beansroperty name="dataSource" ref="DataSourceBean.DEV.dev1"/>
    </beans:bean>


    Thanks
    Last edited by Zenoe; Apr 25th, 2012, 08:13 AM.

  • #2
    I don't believe that JdbcBatchItemWriter itself can handle the situation you want.

    It's possible that you could write a more complex sql statement which would do either/both an insert, and/or an update. The other option is to write your own version of ItemWriter, which could then chose which what sql to run, or could run an update on certain exceptions.

    Comment

    Working...
    X