How to use ElementCollectionField with jpa elementCollection of enum?
I have this field within my jpa entity
@ElementCollection(targetClass = MyEnumType.class)
@CollectionTable(name = "MyTable", joinColumns = @JoinColumn(name = "columnId", nullable = false))
@Column(name = "myField", nullable = false)
@Enumerated(EnumType.STRING)
private Set<MyEnumType> enumTypes;
and this in my form
private ElementCollectionField<MyEnumType> enumType;
public static class MyTypeRow {
EnumSelect<MyEnumType> type = new EnumSelect<MyEnumType>();
}
@Override
protected Component createContent() {
FormLayout layout = new FormLayout();
enumType = new ElementCollectionField<>(MyEnumType.class, MyTypeRow.class)
.withCaption("Types")
.withEditorInstantiator(() -> {
MyTypeRow row = new MyTypeRow();
row.type.setOptions(MyEnumType.values());
return row;
}
);
}
I got a java.lang.InstantiationException. I guess that enum are not supported in ElementCollectionField.
Is there another way to achieve this?