I have a Person object that has a list of addresses. My Spring Batch app converts Person JSON recors into Person POJOs and writes them to a database.
Ordinarily, I'd use JdbcBatchItemWriter but I see it is limited in writing to 2 seperate tables. I need to write to Person and Address table.
Hibernate could write this in one step but I don't see a simialr capability in Spring Bathc.
This SO question Multiple itemwriters in Spring batch suggests using a CompositeItemWriter but the issue with that is, I want my Address table to hold a column called Person_id to link an address back to Person. I won't be able to do that with 2 writes.
Any suggestions? Surely Batch caters for more complex writes
I see from the comment that you can't use an ORM or a service that persists a Person with its addresses. In this case, you can use a custom writer for that:
Another way to do it to delegate to two jdbc batch item writers: