IllegalStateException: Invalid query parameter with name tenantId

Trying to implement Multitenancy, but now can’t login with my (default) admin account

User.java

    @TenantId
    @Column(name = "TENANT")
    private String tenant;

    public String getTenant() {
        return tenant;
    }

    @Override
    public String getTenantId() {
        return tenant;
    }

    public void setTenant(String tenant) {
        this.tenant = tenant;
    }

user-list-view.xml

<column property="tenant"/>

user-detail-view.xml

<comboBox id="tenantField" property="tenant" readOnly="true"/>

LoginView.java

   @Autowired
    MultitenancyUiSupport multitenancyFlowuiSupport;

    private Location currentLocation;

    @Override
    public void beforeEnter(BeforeEnterEvent event) {
        currentLocation = event.getLocation();
        super.beforeEnter(event);
    }

 @Subscribe("login")
    public void onLogin(LoginEvent event) {

        String username = multitenancyFlowuiSupport.getUsernameByLocation(event.getUsername(), currentLocation);

UserDetailView.java

@Autowired
    private TenantProvider tenantProvider;

    @Autowired
    private MultitenancyUiSupport multitenancyUiSupport;

    @Subscribe
    public void onBeforeShow(BeforeShowEvent event) {
        String currentTenantId = tenantProvider.getCurrentUserTenantId();
        if (!currentTenantId.equals(TenantProvider.NO_TENANT)
                && Strings.isNullOrEmpty(tenantField.getValue())) {
            tenantField.setReadOnly(true);
            tenantField.setValue(currentTenantId);
        }
    }

    @Subscribe("tenantField")
    public void onTenantFieldComponentValueChange(AbstractField.ComponentValueChangeEvent<JmixComboBox<String>, String> event) {
        usernameField.setValue(
                multitenancyUiSupport.getUsernameByTenant(usernameField.getValue(), event.getValue())
        );
    }

    @Subscribe
    public void onInit(InitEvent event) {
        timeZoneField.setItems(List.of(TimeZone.getAvailableIDs()));
        tenantField.setItems(multitenancyUiSupport.getTenantOptions());
    }

    @Subscribe
    public void onInitEntity(InitEntityEvent<User> event) {
        tenantField.setReadOnly(false);
        usernameField.setReadOnly(false);
        passwordField.setVisible(true);
        confirmPasswordField.setVisible(true);
    }

Hello Lewis,

Could you please provide full stacktrace of the exception?

An example project to reproduce the exception if possible will be also a great help to investigate the issue.

Regards,
Dmitry

Hi, Lewis

This is a bug, I opened an issue: Incorrect parsing TenantId from UrlQueryParameters · Issue #2207 · jmix-framework/jmix · GitHub
The reason for this bug is that Vaadin of previous versions for some reason parses empty QueriParameters like: Map.of("", "") instead of empty map.
Vaadin Flow Issue: Incorrect handling of empty QueryParameters · Issue #17287 · vaadin/flow · GitHub

In any case, even incorrect parsing should not lead to an error. We’ll fix it.

Regards,
Dmitriy

Thank you Dmitriy, that’s good to know. As my entities are actually linked by a particular value anyway, I can temporarily work around this with Row-Level rules.