Problem filtering propertyCollectionContainer

Hello team,

I’m using propertyCollectionContainer to show a composition on a screen.
Problem is, I need this screen to be responsible only for a subset of the property list.

My entity model is like:

@Entity
@JmixEntity
public class Parent {

    @Id
    @Column(name = "ID", nullable = false)
    @JmixGeneratedValue
    private Long id;

    @Composition
    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "PARENT_ID", nullable = false)
    private Set<Comment> comments;

//... getters and setters
}

@Entity
@JmixEntity
public class Comment {

    @Id
    @Column(name = "ID", nullable = false)
    @JmixGeneratedValue
    private Long id;

    @Column(name = "COMMENT_TYPE")
    private String type;

    @Column(name = "COMMENT_TEXT")
    private String text;

//... getters and setters
}

public enum CommentType implements EnumClass<String> {

    GENERAL("G"),
    OTHER("O");

    private String id;

    CommentType(String value) {
        this.id = value;
    }

    public String getId() {
        return id;
    }

    @Nullable
    public static CommentType fromId(String id) {
        for (CommentType at : CommentType .values()) {
            if (at.getId().equals(id)) {
                return at;
            }
        }
        return null;
    }
}

And have a standart editor screen of Parent having an instance container:

<instance id="parentDc" class="com.company.entity.Parent">
       <fetchPlan extends="_local">
           <property name="comments" fetchPlan="_local"/>
       </fetchPlan>
       <loader/>
       <collection id="commentsDc" property="comments"/>
</instance>

and a table:

<table id="commentsTable" dataContainer="commentsDc">
  <columns>
    <column id="text" />
  </columns>
</table>

Having the given entities and components I need to show only comments of type GENERAL in the table with the option to add more comments to the commentsDc.

I have tried the following:

    @Subscribe
    public void onAfterShow(AfterShowEvent event) {
       commentsDc.setDisconnectedItems(
                getEditedEntity().getComments()
                        .stream()
                        .filter(e -> CommentType.GENERAL.equals(e.getType()))
                        .collect(Collectors.toSet()));
    }

Everything is fine up to here.
Now I want to save a new comment so I do the following:

Comment comment = dataManager.create(Comment.class);
comment.setText(newComment);
comment.setType(CommentType.GENERAL);
commentsDc.getDisconnectedItems().add(comment);

The problem is that comments of type OTHER are deleted.
Also tried using

commentsDc.getMutableItems().add(comment);
and 
commentsDc.getItems().add(comment);

Thanks in advance!
Konstantin

Hi Konstantin,

Looks like you have a test project with entities and screens. Could you attach it here? It would save our time for reproducing the situation.