Tenent coming as null during Springboot

During every startup we found following exception . Why the tenet is set as null . Please advise on this

org.flowable.common.engine.api.FlowableException: Could not find a dataSource for tenant null
at org.flowable.common.engine.impl.cfg.multitenant.TenantAwareDataSource.getCurrentDataSource(TenantAwareDataSource.java:68) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.multitenant.TenantAwareDataSource.getConnection(TenantAwareDataSource.java:56) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138) ~[mybatis-3.5.1.jar:3.5.1]
at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60) ~[mybatis-3.5.1.jar:3.5.1]
at org.apache.ibatis.session.defaults.DefaultSqlSession.getConnection(DefaultSqlSession.java:297) ~[mybatis-3.5.1.jar:3.5.1]
at org.flowable.common.engine.impl.db.DbSqlSessionFactory.openSession(DbSqlSessionFactory.java:96) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.CommandContext.getSession(CommandContext.java:245) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.(StandaloneMybatisTransactionContext.java:48) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.standalone.StandaloneMybatisTransactionContextFactory.openTransactionContext(StandaloneMybatisTransactionContextFactory.java:26) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:47) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:56) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.common.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:51) ~[flowable-engine-common-6.4.2.jar:6.4.2]
at org.flowable.engine.impl.RepositoryServiceImpl.createDeployment(RepositoryServiceImpl.java:88) ~[flowable-engine-6.4.2.jar:6.4.2]
at org.flowable.spring.configurator.DefaultAutoDeploymentStrategy.deployResources(DefaultAutoDeploymentStrategy.java:50) ~[flowable-spring-6.4.2.jar:6.4.2]
at org.flowable.spring.SpringProcessEngineConfiguration.autoDeployResources(SpringProcessEngineConfiguration.java:116) ~[flowable-spring-6.4.2.jar:6.4.2]
at org.flowable.spring.SpringProcessEngineConfiguration.lambda$start$0(SpringProcessEngineConfiguration.java:204) ~[flowable-spring-6.4.2.jar:6.4.2]
at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) ~[na:na]
at org.flowable.spring.SpringProcessEngineConfiguration.start(SpringProcessEngineConfiguration.java:204) ~[flowable-spring-6.4.2.jar:6.4.2]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.0.RELEASE.jar:2.2.0.RELEASE]
at com.ApplicationKt.main(GalaxyApplication.kt:22) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.0.RELEASE.jar:2.2.0.RELEASE]

Do you have a TenantProvider (or DefaultTenantProvider) implementation where you set your tenants?

we have our own tenet provider which we use for hibernate multi tenant handling.

Regards,
Raghu

@joram please assit on this. Let me reply in detail We have used

we have multitenant Liquibase for my application table migration.

We wrote implement CurrentTenantIdentifierResolver and
override AbstractDataSourceBasedMultiTenantConnectionProviderImpl to handle multitendency as mentioned in Hibernate documentation.

Nothing we changed in flowable

we added a class implementing TenantInfoHolder and another service class to invoke and instantiate MultiSchemaMultiTenantProcessEngineConfiguration class

Please assist on this ASAP.

I’m not current on the hibernate documentation wrt to multi tenancy, can you elaborate how it works?
When using MultiSchemaMultiTenantProcessEngineConfiguration, the datasource that is injected (I assume this is the one from Hibernate?) is wrapped in the TenantAwareDataSource from Flowable (this one: https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/multitenant/TenantAwareDataSource.java)

If you injected a TenantInfoHolder, it should hit this line: https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/cfg/multitenant/TenantAwareDataSource.java#L65, where the TenantInfoHolder is used to retrieve the proper datasource. Can you debug that line and see what happens there?

@joram I failed to add below message which came along with Exception .

Exception while autodeploying process definitions. This exception can be ignored if the root cause indicates a unique constraint violation, which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions.

From the above statement, I suspect 2 instance may be a chance. Do I need to exclude any auto configuration class for multitenant ? Please assist on this.

2019-11-22 17:28:59.520 WARN 3988 — [ restartedMain] o.f.s.c.DefaultAutoDeploymentStrategy : Exception while autodeploying process definitions. This exception can be ignored if the root cause indicates a unique constraint violation, which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions.

org.flowable.common.engine.api.FlowableException: Could not find a dataSource for tenant null
        at org.flowable.common.engine.impl.cfg.multitenant.TenantAwareDataSource.getCurrentDataSource(TenantAwareDataSource.java:68) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.cfg.multitenant.TenantAwareDataSource.getConnection(TenantAwareDataSource.java:56) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138) ~[mybatis-3.5.1.jar:3.5.1]
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60) ~[mybatis-3.5.1.jar:3.5.1]
        at org.apache.ibatis.session.defaults.DefaultSqlSession.getConnection(DefaultSqlSession.java:297) ~[mybatis-3.5.1.jar:3.5.1]
        at org.flowable.common.engine.impl.db.DbSqlSessionFactory.openSession(DbSqlSessionFactory.java:84) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.interceptor.CommandContext.getSession(CommandContext.java:245) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.cfg.standalone.StandaloneMybatisTransactionContext.<init>(StandaloneMybatisTransactionContext.java:48) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.cfg.standalone.StandaloneMybatisTransactionContextFactory.openTransactionContext(StandaloneMybatisTransactionContextFactory.java:26) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.interceptor.TransactionContextInterceptor.execute(TransactionContextInterceptor.java:47) ~[flowable-engine-common-6.4.2.jar:6.4.2]
        at org.flowable.common.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:72) ~[flowable-engine-common-6.4.2.jar

Hi,

Please clarify on this ?

In FlowableTenantInfoHolder, clearCurrentTenantId() should be set null or point to default schema? Please advise on this too.

This means that you did not set any tenant on booting up. The exception means that some processes have been tried be deployed on bootup, but no tenant was set. Ideally you set this is some Spring application listener that goes as first.

To null, see e.g. https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/test/java/org/flowable/engine/test/cfg/multitenant/DummyTenantInfoHolder.java#L52 .

Code is executed as follows (from one of the async executors):

public synchronized void run() {
tenantInfoHolder.setCurrentTenantId(tenantId);
super.run();
tenantInfoHolder.clearCurrentTenantId();
}