FlowableException: unknown variable type name jpa-entity

Hi everyone and Flowable team,

I follow guidance on adding JPA support for Flowable in Spring Boot

Everything seems OK. I can:
i) start a process with an assignee
ii) get a list of tasks for an assignee

BUT then I face the below issue when I try to complete a task:

{
"timestamp": "2018-08-24T10:26:02.438+0000",
"status": 500,
"error": "Internal Server Error",
"message": "\n### Error querying database.  Cause: org.flowable.common.engine.api.FlowableException: unknown variable type name jpa-entity\n### The error may exist in org/flowable/variable/service/db/mapping/entity/VariableInstance.xml\n### The error may involve org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntityImpl.selectVariablesByExecutionId\n### The error occurred while handling results\n### SQL: select * from ACT_RU_VARIABLE         where EXECUTION_ID_ = ?         and TASK_ID_ is null\n### Cause: org.flowable.common.engine.api.FlowableException: unknown variable type name jpa-entity",
"path": "/tasks/f6f90ad6-a787-11e8-b0aa-f85971c49eb0"

}

Could you please look into this issue?

To re-produce this issue, please refer to sample project flowable-jpa-demo

Thanks,
Thai

Hi Thai,

It looks like jpa-entity type wasn’t registered while jpa initialization.

Hi,

I’ve checked src code.
It runs FlowableJpaAutoConfiguration class which sets entityManagerFactory so jpa-entity type should be registered. It looks like IbatisVariableTypeHandler contains different variableTypes mapping.
It looks like a bug.

Hi,

Here is a quick workaround:

package com.abc.demo.config;

import java.util.Arrays;

import org.flowable.app.spring.SpringAppEngineConfiguration;
import org.flowable.spring.boot.EngineConfigurationConfigurer;
import org.flowable.variable.service.impl.types.JPAEntityListVariableType;
import org.flowable.variable.service.impl.types.JPAEntityVariableType;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AutoConfigureAfter(SpringAppEngineConfiguration.class)
public class AppEngineConfiguration {

    @Bean
    @ConditionalOnClass(SpringAppEngineConfiguration.class)
    public EngineConfigurationConfigurer<SpringAppEngineConfiguration> customAppEngineConfigurationConfigurer() {

        return appEngineConfiguration -> appEngineConfiguration
                .setCustomPostVariableTypes(Arrays.asList(new JPAEntityVariableType(), new JPAEntityListVariableType()));
    }
}

To be honest I don’t catch it why it works this way. I mean why it uses IbatisVariableTypeHandler created in AppEngineConfiguration instead of ProcessEngineConfiguration.
Maybe someone knows how it works under the hood ?

Hi,

Spring boot starter rest dependency:

<dependency>
  <groupId>org.flowable</groupId>
  <artifactId>flowable-spring-boot-starter-rest</artifactId>
  <version>6.3.2-SNAPSHOT</version>
</dependency>

brings AppEngineConfiguration.

I’ve checked source code and I see that AppEngineCongiration and ProcessEngineCnfiguration share sqlSessionFactory (see AppEngineConfiguration.configuratorsAfterInit)

But it looks like a feature not a bug :slight_smile:
Check this code:

It initializes sessionFactory and then invokes:

configuratorsAfterInit() which copies sqlSessionFactory from AppEngineCongiration to SpringProcessEngineConfiguration so it’s the reason why IbatisVariableTypeHandler doesn’t see jpa-entity type.

You can easily reproduce this issue adding:

     <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter-rest</artifactId>
    </dependency>

to flowable-spring-boot-sample-jpa project and then run JpaApplicationTest

Hi,

Thanks for the feedback and analysis.
For your purpose, you could also use the flowable-spring-boot-starter-process-rest module instead of the one you are using now. Then it will work. But we do need a way to make this work with the app engine included as well of course.

Best regards,

Tijs

Hello,

For information, I have the same (?) problem on Flowable Admin UI 6.3.1 when listing instance variables on a process instance that contains a jpa entity (clicking on “Variables” from http://localhost:8080/flowable-admin/#/process-instance/myPid):

org.flowable.ui.admin.service.engine.exception.FlowableServiceException:

Error querying database. Cause: org.flowable.common.engine.api.FlowableException: unknown variable type name jpa-entity

The error may exist in org/flowable/variable/service/db/mapping/entity/HistoricVariableInstance.xml

The error may involve org.flowable.variable.service.impl.persistence.entity.HistoricVariableInstanceEntityImpl.selectHistoricVariableInstanceByQueryCriteria

The error occurred while handling results

SQL: select * from ( select a., ROWNUM rnum from ( select RES. from ACT_HI_VARINST RES WHERE RES.PROC_INST_ID_ = ? order by NAME_ asc ) a where ROWNUM < ?) where rnum >= ?

Cause: org.flowable.common.engine.api.FlowableException: unknown variable type name jpa-entity

at org.flowable.ui.admin.service.engine.FlowableClientService.executeRequest(FlowableClientService.java:150) ~[flowable-ui-admin-logic-6.3.1.jar:6.3.1]
at org.flowable.ui.admin.service.engine.FlowableClientService.executeRequest(FlowableClientService.java:118) ~[flowable-ui-admin-logic-6.3.1.jar:6.3.1]
at org.flowable.ui.admin.service.engine.FlowableClientService.executeRequest(FlowableClientService.java:114) ~[flowable-ui-admin-logic-6.3.1.jar:6.3.1]
at org.flowable.ui.admin.service.engine.ProcessInstanceService.getVariables(ProcessInstanceService.java:142) ~[flowable-ui-admin-logic-6.3.1.jar:6.3.1]
at org.flowable.ui.admin.rest.client.ProcessInstanceClientResource.getVariables(ProcessInstanceClientResource.java:74)

I tried adding the SpringAppEngineConfigurer like proposed above, but until now I wasn’t able to make it work. I also added the 2 other types “HistoricJPAEntityVariableType” and “HistoricJPAEntityListVariableType”.
Any tip on how to do this would be welcome…

Best regards,

Sophie

Hi @rgorzkowski and @tijs,

Thanks for your reply. Very good to know that AppEngineConfiguration and ProcessEngineConfiguration share sqlSessionFactory!

Back to the issue, I am not so sure if it is a bug, hence I did not open a github issue for this. Not agreeable it is a feature either :joy:

Thanks @rgorzkowski for the workaround. This is something similar that I have tried out and it works.
To fix the issue, basically I have created an extension to help create new jpa-entity via setValue method. That is actually a custom jpa variable type and very similar to but not extended the JPAEntityVariableType. Then register it:
> public class ProcessEngineConfigurer implements EngineConfigurationConfigurer {

    @Override
    public void configure(SpringProcessEngineConfiguration engineConfiguration) {
        List<VariableType> customVariableTypes = new ArrayList<>();
        customVariableTypes.add(new JPAEntityVariableType());
        engineConfiguration.setCustomPreVariableTypes(customVariableTypes);
    }

I wonder if it is a right way to do as I am having kind of 2 jpa variable types inside the engine.

Thanks,
Thai

1 Like

Hi Thai,

Do you need SpringAppEngineConfiguration in your project ?
If not you can also exclude SpringAppEngineConfiguration by changing dependency, as @tijs said .

From:

   <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter-rest</artifactId>
        <version>6.3.2-SNAPSHOT</version>
    </dependency>

To:

     <dependency>
        <groupId>org.flowable</groupId>
        <artifactId>flowable-spring-boot-starter-process-rest</artifactId>
        <version>6.3.2-SNAPSHOT</version>
    </dependency>

I’ve checked it and it works.

Hi Sophie,

Can you create (on github) sample repo with your issue ?
I can dig into it.

Thanks @rgorzkowski for looking into this. To provide some more clarity. When multiple engines are running then one of the engine takes the “lead” and is responsible for initializing the database, configuring the session factory etc. When the app engine is present that this engine is the lead.

This means that the VariableTypes which are used will not be the one from the process engine configuration, but the ones from the AppEngine. I think that something needs to be done in the ProcessEngineConfigurator.

@rgorzkowski I think that if one creates a copy of the flowable-spring-boot-sample-jpa and use the flowable-spring-boot-starter that it should be enough for reproducing this problem (as you already noticed)

Cheers,
Filip

Hi @rgorzkowski,

I do not need SpringAppEngineConfiguration for now but might need it in later phase of our project. I changed to only use

flowable-spring-boot-starter-process-rest

as per your and @tijs advice and it works, so no further question for this.

Now, could you please advise if there is any concern with the approach (2 jpa variable types initialized) in my previous post?

Thanks,
Thai

Hi @thaingo ,

Regarding your previous post.
Frankly speaking I don’t know how is it possible that it works.
If you set customPreVariables on ProcessEngineConfiguration and AppEngineConfiguration exists on classpath, the App engine is the lead as @filiphr said so this code from ProcessEngineConfiguration won’t be invoked:

 @Override
public void initMybatisTypeHandlers(Configuration configuration) {
    configuration.getTypeHandlerRegistry().register(VariableType.class, JdbcType.VARCHAR, new IbatisVariableTypeHandler(variableTypes));
}

But I might be wrong. Do you have any example project on github ?

Now, could you please advise if there is any concern with the approach (2 jpa variable types initialized) in my previous post?

I don’t have enough experience in Flowable so it’s hard to say. But I think that you will have problems with history deatails (check HistoricJPAEntityVariableType usage - https://github.com/flowable/flowable-engine/blob/eeebfd23af3571741b60e3f663f17c0ecc50a812/modules/flowable-engine/src/main/java/org/flowable/engine/impl/HistoricDetailQueryImpl.java#L135 )

Hi,

Concerning the probably related flowable ui admin problem: I pushed my code to https://github.com/soframel/flowable-spring-testjpa
It is only used to create a process instance with a JPA entity as a variable named “entity” (launch the class org.soframel.tests.flowable.spring.StartProcess).
But the code works fine: the problem is that later if you configure flowable-admin to use the same DB (in ~/flowable-db/db), and you browse to the process instance variable list, you get the exception “unknown variable type name jpa-entity”.

best,

Sophie

Hello,
I’m starter with flowable, i got the same error Capture
Event that i add the dependency “flowable-spring-boot-starter-process-rest”
but also i got the same error please can any one help me with easy steps
Thanks in advance