I am having a requirement to write into 2 tables header and Line table. After reading and processing I am saving the result into a list of Objects. In the writer I need to get each object from list and write into Header table(One row), get the ID of the primary Key for the row inserted and then use this Key as a Foreign key of Line table during insert.
I have 2 problems here: 1. Reading the list in item writer from list. I have used below 2 links to write this: Spring Batch - Using an ItemWriter with List of Lists Writing List of Items using JdbcBatchItemWriter
But getting the error:
java.lang.NullPointerException: null at org.springframework.batch.item.database.JdbcBatchItemWriter.write(JdbcBatchItemWriter.java:186) ~[spring-batch-infrastructure-4.2.1.RELEASE.jar:4.2.1.RELEASE]
- How to implement one to many mapping. One solution suggested is to write a custom service method: Spring Batch - write to 2 tables at once
Is it right to call another service method inside from writer?
Thanks, BR