Multi Tenancy : find fails with a NPE on DN 2.5.6


stephane
 

I'm trying to use datanucleus.TenantReadIds at the EntityManager level, setting this property entityManager.setProperty(PropertyNames.PROPERTY_MAPPING_TENANT_READ_IDS, tenant);

As it doesn't seems applied, I look at PersistenceNucleusContextImpl:getMultiTenancyReadIds

public String[] getMultiTenancyReadIds(ExecutionContext ec)
{
if (multiTenancyProvider != null)
{
String[] tenantReadIds = multiTenancyProvider.getTenantReadIds(ec);
return (tenantReadIds != null) ? tenantReadIds : new String[] {multiTenancyProvider.getTenantId(ec)};
}

String readIds = config.getStringProperty(PropertyNames.PROPERTY_MAPPING_TENANT_READ_IDS);
if (readIds != null)
{
// Return the tenant read ids if defined (for context)
return readIds.split(",");
}

// Fallback to just the current tenant id for this execution context
return new String[] {ec.getStringProperty(PropertyNames.PROPERTY_MAPPING_TENANT_ID)};
}

Is it possible to read the PROPERTY_MAPPING_TENANT_READ_IDS from the EntityManger settings before doing the fallback ? 

thanks,
--
Stephane


stephane
 
Edited

On Sat, Feb 27, 2021 at 01:22 AM, <passignat@...> wrote:
multiTenancyProvider

Case: https://github.com/datanucleus/datanucleus-core/issues/365
I think it's available in this fix
DN Version: 5.2.7

thanks Andy 
--
Stephane


stephane
 

Unable to set the multitenant properties (on current source):

props.put(PropertyNames.PROPERTY_MAPPING_TENANT_READ_IDS, tenant);
props.put(PropertyNames.PROPERTY_MAPPING_TENANT_ID, tenant);
final EntityManager entityManager = emf.createEntityManager(props);
Has no effect.

entityManager
.setProperty(PropertyNames.PROPERTY_MAPPING_TENANT_READ_IDS, tenant);
Raise this log
WARN   Attempt to set property "datanucleus.TenantReadIds" on PM/EM yet this is not supported. Ignored

I tried to set these properties in the EMF properties without more success.


Any suggestions ?

--
Stephane


stephane
 

Using properties.setProperty(PropertyNames.PROPERTY_MAPPING_TENANT_PROVIDER,MyTenantProvider.class.getName()) raises an error

WARN   Error accessing property datanucleus.TenantProvider; should be an instance of MultiTenancyProvider but isnt! Ignored
--
Stephane


stephane
 
Edited

Miss read the doc. TenantProvider need to be an object in the EntityManager setting.

Map map = new HashMap();
map.put(PropertyNames.PROPERTY_MAPPING_TENANT_PROVIDER, new MyTenantProvider());
final EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("APP_UNIT", map);

So far TenantProvider works with JPA, remains to understand why TenantReadIds on the EntityManger doesn't...
--
Stephane