Hi John,
Regarding WORDSJAVA-1250, our product team has completed the work on your issue and has come to a conclusion that this issue and the undesired new behaviour you’re observing is actually not a bug. So, we will close this issue as ‘Not a Bug’.
The problem occurs because of incorrect usage of DataTable and DataRelations. There are three ways to achieve the goal.
- Add parent’s row before child’s one. Have a look at the concept
:
The FOREIGN KEY constraint also prevents invalid data from being inserted into the foreign key column, because it has to be one of the values contained in the table it points to.
-
Use DataTable.setEnforceConstraints(false) before adding a row.
-
Use DataRelation(String relationName, DataColumn[] parentColumns, DataColumn[] childColumns, boolean createConstraints=false)
As we can see you try to add child’s row before parent’s one. See the following corrected example of fist approach. See the code with comments.
DataRelation riskDetailsRelation = new DataRelation(
“RiskToRiskDetails”,
riskDataTable /parent table/,
riskDetailsDataTable /* child table which depends on parent via 'riskIDString*/,
new String[]{“riskIDString”}, new String[]{“riskIDString”});
allRiskData.getRelations().add(riskDetailsRelation);
DataRow row = riskDataTable.newRow(); // At the moment it is detached and needs to be add into collection.
//Risk Data.
// This is the parent row. All children want to make sure this row exists and riskIDString presented
row.set(0, “_9999”);
row.set(1, “”);
row.set(2, “”);
row.set(3, “filldata”);
row.set(4, “”);
row.set(5, “”);
row.set(6, “”);
row.set(7, “”);
row.set(8, “”);
row.set(9, “”);
row.set(10, “”);
row.set(11, “”);
row.set(12, “”);
row.set(13, “”);
row.set(14, “filldata”);
row.set(15, “”);
row.set(16, “”);
row.set(17, “”);
row.set(18, “”);
row.set(19, “”);
row.set(20, “”);
row.set(21, “”);
riskDataTable.getRows().add(row);
DataRow detailsRow = riskDetailsDataTable.newRow(); //child row
detailsRow.set(0, “_9999”);
detailsRow.set(1, “”);
detailsRow.set(2, “5”);
detailsRow.set(3, “”);
detailsRow.set(4, “”);
detailsRow.set(5, “”);
detailsRow.set(5, “”);
detailsRow.set(6, “”);
detailsRow.set(7, “”);
detailsRow.set(8, “”);
detailsRow.set(9, “”);
//Because ‘riskDataTable’ and ‘riskDetailsDataTable’ are connected with riskIDString lets make sure ‘riskDataTable’ has a row with ‘riskIDString’ presented
// check riskDataTable
DataSetWriter.printDataTable(riskDataTable);
// riskDetailsDataTable.setEnforceConstraints(false); // Another way is to just switch off the constraints before adding
riskDetailsDataTable.getRows().add(detailsRow);
// check if child’s row has been added correctly.
DataSetWriter.printDataTable(riskDetailsDataTable);
Hope, this helps.
Best regards,