• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Multiple table Insertions using JdbcBatchItemWriter

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Appreciate if any thoughts on this.
 
Skanda Raman
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic