Hi,
I have problem with the transaction when i use two writers with CompositeItemWriter. I have a writer to write lines in files and a writer to insert data in database.
The transaction of JdbcBatchItemWriter isn't managed by the transaction manager. Each call of write method commit the insert. I would like that the commit is called in same time that the commit managed by the transactionManager.
My first writer, a FlatFileItemWriter work good. The lines is flush in my file only when the commit is called by the transaction manager.
This is a big problem because when the first writer (the JdbcBatchItemWriter) succeed and the second writer (flatFileItemWriter) crash, the insert is already commit. It's not good.
So, How precised to JdbcBatchItemWriter to commit in same time that the transactionManager ??
I see in the JavaDoc of the JdbcBatchItemWriter class the line below but i don't find the solution :
Below, a party of my application context :Code:It is expected that write(List) is called inside a transaction.
Code:<!-- Liste des writers --> <beans:bean id="myItemWriter" class="org.springframework.batch.item.support.CompositeItemWriter"> <beans:property name="delegates"> <beans:list> <beans:ref bean="sqlItemWriter" /> <beans:ref bean="fileItemWriter" /> </beans:list> </beans:property> </beans:bean> <!-- Ecrit les items dans des fichiers --> <beans:bean id="fileItemWriter" scope="step" class="com.kevin.FileItemWriter"> <beans:property name="path" value="#{jobParameters[output.file.path]}" /> <beans:property name="util" ref="util" /> </beans:bean> <!-- Une insertion en base par item --> <beans:bean id="sqlItemWriter" class="org.springframework.batch.item.database.JdbcBatchItemWriter"> <beans:property name="dataSource" ref="p2dDataSource" /> <beans:property name="itemPreparedStatementSetter"> <beans:bean class="com.kevin.MyPreparedStatementSetter" /> </beans:property> <beans:property name="sql" value="INSERT INTO P2CAPCACCL VALUES (?, ?)" /> </beans:bean>
Thanks for advance.


Reply With Quote