Being new to Spring Batch, I am making a good progress by exploring some POCs. One of the POCs I am currently working on is about reading data from csv file and loading into database tables which have parent child relationships.
CSV file now contains customers and orders info as below.
- custname1, custaddress1, custzip1, orderdate11, ordervalue11, ordertax11
- custname1, custaddress1, custzip1, orderdate12, ordervalue12, ordertax12
- custname2, custaddress2, custzip2, orderdate21, ordervalue21, ordertax21
- custname2, custaddress2, custzip2, orderdate22, ordervalue22, ordertax22
These data will be loaded into DB tables Customer, Order where CustId and OrderId will be auto generated by Oracle Sequences and table Order has CustId as a foreign key for maintaining 1 to many relationship ( 1 Customer can have multiple Orders )
FlatFileItemReader, FieldSetMapper, ItemWriter are the interfaces I am employing in this POC and I am using JdbcTemplate for DB operations.
I have following questions. Please clarify.
1) How to design my Reader bean?
The model class Customer has its members, getters and setters methods. Same with model class Order.
Should Customer class ( reading data from CSV file ) contain a member for Order class and corresponding getter, setter methods in order to represent Parent - Child Relationship?
2) How to retrieve primary key which I am currently creating it within the INSERT sql for Customer using sequence.nextval?
3) How to store all the Primary Keys from Parent data bulk load and then use them for foreign key in Child table data load ?
Thanks.