I have a C # application that should insert one parent record and at least four children records in a hierarchical order. IOW, the parent contract applies to one or more locations, each location has one or more elements, each element has one or more services, and each service has one or more requirements. The application first receives a set of Oracle sequence numbers, one from each sequence of tables for each record. For some reason (outdated database), each record has not only its parent serial number, but also the serial number of the contract.
So, the code starts the transaction, inserts the parent with the parent number of the parent level, then tries to insert the location record already populated with both the parent number and FK, and its own table serial number. However, I get an Oracle-02291 error that the FK violates because the parent number was not found.
INSERT into Contracts (contract_sequence_number, ...) values (10437, ...); INSERT into Locations (location_sequence_number, contract_sequence_number, ...) values (23733, 10437, ...); ...
I suppose this is because the parent was not perfect and therefore unavailable. However, I cannot commit the parent if any of the child records failed, so there is no commit before inserting the child.
I know this is such a common scenario, the answer should be pre-noob. But all the answers that I found so far imply that the parent sequence number is found "in the table" to satisfy the FK.
Any thoughts on how I can fix this are greatly appreciated.
Randy
source share