JPAContainer and FieldFactory ComboBox sorting

Hello, I have a simple ComboBox presenting a list of entities, which is backed by JPAContainer.
When I use this ComboBox “normally” by adding it to a layout, the entity sorting is working properly:

MunicipalitySelector    homeMunicipality    = new MunicipalitySelector("Municipality");

addComponent(homeMunicipality);

Homever, this is not the case when building the form (for a Person entity) automatically with FieldFactory:

setSingleSelectType(Municipality.class, MunicipalitySelector.class);


The entities are always sorted by their id’s and the sorting property is ignored.

I am defining the sorting this way in the ComboBox:

JPAContainer<Municipality> container = JPAContainerFactory.make(Municipality.class, Application.PERSISTENCE_UNIT);
container.setApplyFiltersImmediately(false);
container.sort(new String[] { Municipality.NAME }, new boolean[]
 { true });

setConverter(new SingleSelectConverter<Municipality>(this));
setContainerDataSource(container);

        for (Object id : container.getItemIds()) {
            Municipality m = container.getItem(id).getEntity();
            setItemCaption(id, m.getName());
        }

The Municipality entity is linked to a Person entity via @ManyToOne(fetch = FetchType.LAZY), using EclipseLink.

Can this have something to do with FieldFactory’s way of instantiating a .newInstance() of the selector? I have debugged the selector code and made sure container.sort() is executed, but somehow it’s still suspicious.

Or can it be a bug in FieldFactory somehow overriding the container sorting?

Thanks for your time!

Greetings,
13450.png

For anyone’s future reference, the culprit was FieldFactory overriding select container, which caused most settings to be lost:

    protected Field createManyToOneField(EntityContainer containerForProperty, Object itemId, Object propertyId, Component uiContext) {
        Class<?> type = containerForProperty.getType(propertyId);
        JPAContainer container = createJPAContainerFor(containerForProperty, type, false);

        AbstractSelect nativeSelect = constructReferenceSelect(containerForProperty, itemId, propertyId, uiContext, type);
        nativeSelect.setMultiSelect(false);
        nativeSelect.setCaption(DefaultFieldFactory.createCaptionByPropertyId(propertyId));
        nativeSelect.setItemCaptionMode(NativeSelect.ITEM_CAPTION_MODE_ITEM);
        [b]
nativeSelect.setContainerDataSource(container);
[/b]
        nativeSelect.setConverter(new SingleSelectConverter(nativeSelect));
        return nativeSelect;
    }