Multitenancy not working?

Version Add-on: 2.0.0.BETA1
Version Studio: 13.0
Version Framework: v7.2.0

I’m trying to achieve a very simple example:

import com.haulmont.addon.sdbmt.entity.StandardTenantEntity;
import com.haulmont.chile.core.annotations.NamePattern;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@NamePattern("%s|name")
@Table(name = "APPATOM_DOCUMENT_TYPE")
@Entity(name = "appatom_DocumentType")
public class DocumentType extends StandardTenantEntity {
    private static final long serialVersionUID = 1854489626758796679L;

    @NotNull
    @Column(name = "NAME", nullable = false)
    protected String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
  1. Created a Admin User for the specific tenant
  2. Created a new tenant
  3. Created a standard browse/edit entity screen.
  4. Logged in with tenant user.

Problem is when adding a new document type it’s shown in screen a new entry in the browse screen.
image
When clicking refresh i see the entries disappear.
image
Looking at the entity inspector i see records getting created without the tenant ID.
image

Hello, @mrfloppy1980

Thanks for reporting the problem. We created an issue.

Regards,
Nikita

@shchienko Thank you for responding and creating the issue on github!

Is there a workaround available for this moment?

Hello, @mrfloppy1980

You need to add the listener:

@Component("multitenancy_EntityChangedListener")
public class MultitenacyEntityPersistingListener {

    @Inject
    protected TenantProvider tenantProvider;

    @Inject
    protected TenantEntityOperation tenantEntityOperation;

    @EventListener
    public void beforePersist(EntityPersistingEvent event) {
        Entity entity = event.getEntity();
        String tenantId = tenantProvider.getCurrentUserTenantId();
        if ((entity instanceof HasTenant || entity instanceof TenantEntity) && !tenantId.equals(TenantProvider.NO_TENANT)) {
            tenantEntityOperation.setTenant(entity, tenantId);
        }
    }
}

Regards,
Nikita