When creating a new record which contain a Composition record, a WRONG FOREIGN KEY was used.
The Foreign Key used to insert is another status history table one, which is created by the SQL server database insert trigger fire by the master table.
If I disable the insert trigger, the cuba application become resume normal.
The Composition record was added by the following code.
@Subscribe("dummyList")
public void onDummyListValueChange(HasValue.ValueChangeEvent<B011ProjectScheme> event) {
if (event.isUserOriginated()) {
D011IssueScheme aIssueScheme = metadata.create(D011IssueScheme.class);
D011IssueScheme newIssueScheme = dataContext.merge(aIssueScheme);
B011ProjectScheme oneProjectScheme = dataManager.load(B011ProjectScheme.class)
.query("e.project.id = :project and e.projectSchemeCode = :sCode")
.parameter("sCode", event.getValue().getProjectSchemeCode())
.parameter("project", prjidLookUp.getValue().getId().intValue())
.one();
newIssueScheme.setIssue(getEditedEntity());
newIssueScheme.setProjectSchemeId(oneProjectScheme);
newIssueScheme.setProjectSchemeCode(oneProjectScheme.getProjectSchemeCode());
issueSchemeDc.getMutableItems().add(newIssueScheme);
dummyList.setValue(null);
}
}
It seem to be a Cuba application bug. As our database trigger perform many checking to insert status history, we cannot disable it.
Any suggestion to prevent this problem, thanks.