Announcement Announcement Module
No announcement yet.
Multiple table Insertions using JdbcBatchItemWriter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multiple table Insertions using JdbcBatchItemWriter


    I have a requirement to insert data into two tables using JdbcBatchItemWriter.

    I have two tables TABLE_A, TABLE_B.

    TABLE_B is child of TABLE_A with Foreign Key Relation. I am successful on inserting data using this batch writer to TABLE_A.

    However, due to FK constraint, I cannot know the FK value to insert in TABLE_B.

    Please let me know if there is a way to get the primary key values for the records inserted in TABLE_A during the process so that I can build a object and itemwrite into TABLE_B.

  • #2
    Additionally I wanted to mention that, the PK for TABLE_A is a sequence which generates automatically. Hence, even when I try to use the CompositeItemWriter, I cannot reuse the Object for next table writers.

    However, I tried to insert data for TABLE_A initially using simpleJdbcInsert and get the PK value and then use JDBCBatchWriter to write other tables.

    This approach seems to be more time consuming which hits the performance when there are huge records.

    Here is the insert script I am trying to Execute through JdbcBatchItemWriter. I want to use the same seq id in TABLE_B.


    Hope this info helps. Let me know if there is a way in spring/spring batch to do this.

    Appreciate if any thoughts on this.
    Last edited by reference2me; Jul 8th, 2013, 10:24 AM. Reason: Adding more information.