Problem on update COMPOSITION data collection table by getMutableItems()

I use a lookupField to add record in a COMPOSITION data collection. For remove record I used a generated column. I got 2 problem in below code.

  1. After “Save”, all removed COMPOSITION table record still exists.
    In Edit mode without any problem on adding record, but the removed record after save edit again all come back.

  2. Cannot save the added record in Create mode.
    When added record in COMPOSITION table on a NEW issue, the following error display.
    圖片

	<instance id="issueDc" class="com.yyy.xxx.entity.Issue">
		<view extends="_local">
			<property name="issueScheme" view="_minimal"/>
		</view>
		<loader/>
		<collection id="issueSchemeDc" property="issueScheme"/>
	</instance>

	......

	<lookupField id="dummyList" caption="Project Scheme" optionsContainer="projectSchemeDc"/>
	<groupTable id="issueSchemeTable" dataContainer="issueSchemeDc" width="100%" height="120"
				stylename="no-header borderless no-vertical-lines no-horizontal-lines no-stripes small">
		<columns>
			<column id="projectSchemeCode"/>
		</columns>
	</groupTable>
    @Subscribe
    public void onInit(InitEvent event) {        
        issueSchemeTable.addGeneratedColumn("Remove",1, entity -> {
            LinkButton field = uiComponents.create(LinkButton.class);
            field.setCaption("");
            field.setIcon("icons/remove.png");
            field.setAction(new BaseAction("viewDescDetail")
                    .withCaption("View Description Detail")
                    .withHandler(clickEvent -> {
                        issueSchemeDc.getMutableItems().remove(issueSchemeTable.getSingleSelected());
                    })
            );
            return field;
        });
    }

    @Subscribe("dummyList")
    public void onDummyListValueChange(HasValue.ValueChangeEvent<ProjectScheme> event) {
        if (event.isUserOriginated()) {
            issueScheme newIssueScheme = metadata.create(issueScheme.class);
            newIssueScheme.setIssue(d01IssueDc.getItem());
            newIssueScheme.setProjectSchemeId(event.getValue().getProjectSchemeCode());
            newIssueScheme.setProjectSchemeCode(oneProjectScheme.getProjectSchemeCode());
            issueSchemeDc.getMutableItems().add(newIssueScheme);
            dummyList.setValue(null);
        }
    }	

Hi,

For discussion about removal see this topic.

For discussion about creation see this topic.

Thanks Maxim,

The removal problem was solved.

Also no problem on edit mode, but when I create new record another SQL error occur.
“SQLServerException: The INSERT statement conflicted with the FOREIGN KEY constraint”

I’m using SQL server as database, all table use have a Int Identity column.
I found that when I create new record, the system not using the same identity number of getEditedEntity() one to save the new record, so the foreign key error occour.

Any Idea on this error?