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

  • Multiple table Insertions using JdbcBatchItemWriter

    Hello,

    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.

    INSERT INTO TEST_A(TEST_A.nextval,NAME)

    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, 11:24 AM. Reason: Adding more information.

    Comment

    Working...
    X