Primary reference to the header record being overwritten.
Posted: Wed Oct 07, 2015 1:50 pm
I have a project set to read the xml and insert the data values into database table.
xml file is somewhat like this :
<?xml version="1.0" encoding="UTF-8"?>
<CHARGES>
<partner>abc</partner>
<CHARGE>
<chargetype>charge1</chargetype>
<chargevalue>something</chargevalue>
<CHARGE_DETAIL>
<CHARGE_TYPE>FUEL charge1</CHARGE_TYPE>
<CHARGE_AMOUNT>2.12</CHARGE_AMOUNT>
</CHARGE_DETAIL>
<CHARGE_DETAIL>
<CHARGE_TYPE>FUEL charge1</CHARGE_TYPE>
<CHARGE_AMOUNT>3</CHARGE_AMOUNT>
</CHARGE_DETAIL>
</CHARGE>
<CHARGE>
<chargetype>charge2</chargetype>
<chargevalue>somethingelse</chargevalue>
<CHARGE_DETAIL>
<CHARGE_TYPE>weighing station</CHARGE_TYPE>
<CHARGE_AMOUNT>10</CHARGE_AMOUNT>
</CHARGE_DETAIL>
<CHARGE_DETAIL>
<CHARGE_TYPE>lunchbreak</CHARGE_TYPE>
<CHARGE_AMOUNT>6</CHARGE_AMOUNT>
</CHARGE_DETAIL>
</CHARGE>
</CHARGES>
i have to read the values of header and details and insert it into the respective tables.
I generate a primary key for header and detail and the header_id is the foreign key in the details table.
if there is only one charge, it works like a charm , but if there are multiple charges reported , then I am loosing the header_id craeted if the first rowset.
not sure how to proceed.
but if there are multiple charges, then
so in the above scenario,
i should expect to see data like this :
header_charge_table
hdrid partner , col1, col2
10 abc charge1 somethign
11 abc charge2 somethignelse
details_charge_table should have :
id hdrid charge_type charge_amount
1 10 xyz 2
2 10 hij 3
3 11 rst 10
4 11 klm 6
whereas what is happening is :
header table reflects the correct records, but details table gets the foreign key as 11 for all of the rows.
any help will be appreciated.
xml file is somewhat like this :
<?xml version="1.0" encoding="UTF-8"?>
<CHARGES>
<partner>abc</partner>
<CHARGE>
<chargetype>charge1</chargetype>
<chargevalue>something</chargevalue>
<CHARGE_DETAIL>
<CHARGE_TYPE>FUEL charge1</CHARGE_TYPE>
<CHARGE_AMOUNT>2.12</CHARGE_AMOUNT>
</CHARGE_DETAIL>
<CHARGE_DETAIL>
<CHARGE_TYPE>FUEL charge1</CHARGE_TYPE>
<CHARGE_AMOUNT>3</CHARGE_AMOUNT>
</CHARGE_DETAIL>
</CHARGE>
<CHARGE>
<chargetype>charge2</chargetype>
<chargevalue>somethingelse</chargevalue>
<CHARGE_DETAIL>
<CHARGE_TYPE>weighing station</CHARGE_TYPE>
<CHARGE_AMOUNT>10</CHARGE_AMOUNT>
</CHARGE_DETAIL>
<CHARGE_DETAIL>
<CHARGE_TYPE>lunchbreak</CHARGE_TYPE>
<CHARGE_AMOUNT>6</CHARGE_AMOUNT>
</CHARGE_DETAIL>
</CHARGE>
</CHARGES>
i have to read the values of header and details and insert it into the respective tables.
I generate a primary key for header and detail and the header_id is the foreign key in the details table.
if there is only one charge, it works like a charm , but if there are multiple charges reported , then I am loosing the header_id craeted if the first rowset.
not sure how to proceed.
but if there are multiple charges, then
so in the above scenario,
i should expect to see data like this :
header_charge_table
hdrid partner , col1, col2
10 abc charge1 somethign
11 abc charge2 somethignelse
details_charge_table should have :
id hdrid charge_type charge_amount
1 10 xyz 2
2 10 hij 3
3 11 rst 10
4 11 klm 6
whereas what is happening is :
header table reflects the correct records, but details table gets the foreign key as 11 for all of the rows.
any help will be appreciated.