1

I'm trying to implement a few tests with JBPM 6. I'm currently working a a simple hello world bpmn2 file, which is loaded correctly.

My understading of the documentation ( Click ) is that persistence should be disabled by default. "By default, if you do not configure the process engine otherwise, process instances are not made persistent."

However, when I try to implement it, and without doing anything special to enable persistence, I hit persistence related problems every time I try to do anything.

javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.persistence.jpa
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at org.jbpm.runtime.manager.impl.jpa.EntityManagerFactoryManager.getOrCreate(EntityManagerFactoryManager.java:33)
    at org.jbpm.runtime.manager.impl.DefaultRuntimeEnvironment.init(DefaultRuntimeEnvironment.java:73)
    at org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder.get(RuntimeEnvironmentBuilder.java:400)
    at org.jbpm.runtime.manager.impl.RuntimeEnvironmentBuilder.get(RuntimeEnvironmentBuilder.java:74)</blockquote>

I Create my runtime environement the following way,

RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get()
            .newDefaultInMemoryBuilder()
            .persistence(false)
            .addAsset(ResourceFactory.newClassPathResource("examples/helloworld.bpmn2.xml"), ResourceType.BPMN2)
            .addAsset(ResourceFactory.newClassPathResource("examples/newBPMNProcess.bpmn"), ResourceType.BPMN2)
            .get();

As my understanding is that persistence should be disabled by default, I don't see what I'm doing wrong. It could be linked to something included in some of my dependencies, but I don't have found anything on it either.

Has anybody faced the same issue already or has any advice.

Thanks

Krohm
  • 11
  • 2
  • 1
    Have you solved this? I too am confused about the jBPM documentation regarding persistence, as they explicit say that by default it's not being used (http://docs.jboss.org/jbpm/v6.2/userguide/jBPMPersistence.html#d0e5721) – Fappaz Jul 27 '15 at 05:12

2 Answers2

1

A RuntimeManager is a combination of a process engine and a human task service. The human task service needs persistence (to start the human tasks etc.), that's why it's still asking for a datasource, even if you configure the engine to not use persistence.

If you want to use an engine without our human task service, you don't need persistence at all, but I wouldn't use a RuntimeManager in that case, simply create a ksession from the kbase directly: http://docs.jboss.org/jbpm/v6.1/userguide/jBPMCoreEngine.html#d0e1805

Kris Verlaenen
  • 2,918
  • 1
  • 15
  • 5
  • I'm facing exactly the same issue. When I try to create a ksession from a kbase, it complains about human tasks: `Exception in thread "main" org.jbpm.workflow.instance.WorkflowRuntimeException: [defaultPackage.New_Process:1 - Form:6] -- Could not find work item handler for Human Task` If I'm not using human tasks, why is it still complaining that way? – Fappaz Jul 15 '15 at 05:10
  • About the above-mentioned issue, I had to register a WorkItemHandler in my session anyway. – Fappaz Jul 21 '15 at 22:58
0

The InMemoryBuilder which you use in your code is supposed to (as per API documentation) not be persistent, but it is actually adding a persistence manager to the environment, just with an InMemoryMapper instead of a JPAMapper because of the way the init() method in DefaultRuntimeEnvironment is implemented:

public void init() {
    if (emf == null && getEnvironmentTemplate().get(EnvironmentName.CMD_SCOPED_ENTITY_MANAGER) == null) {
        emf = EntityManagerFactoryManager.get().getOrCreate("org.jbpm.persistence.jpa");
    }   
    addToEnvironment(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
    if (this.mapper == null) {
        if (this.usePersistence) {
            this.mapper = new JPAMapper(emf);
        } else {
            this.mapper = new InMemoryMapper();
        }
    }
}

As you can see above, this still tries to getOrCreate() a persistence unit (I have seen a better implementation which also checks for the value of persistence attribute somewhere, but the issue here is, DefaultRuntimeEnvironment doesn't do that).

What you need to start with to get away without persistence is a newEmptyBuilder():

RuntimeEnvironment env = RuntimeEnvironmentBuilder.Factory.get()
            .newEmptyBuilder()
            .knowledgeBase(KieServices.Factory.get().getKieClasspathContainer().getKieBase("my-knowledge-base"))
            // ONLY REQUIRED FOR PER-REQUEST AND PER-INSTANCE STRATEGY
            //.addEnvironmentEntry("IS_JTA_TRANSACTION", false)
            .persistence(false)
            .get();

Do mind though that this will only work for Singleton runtime managers - PerProcessInstance and PerRequest expect to be able to suspend a running transaction if necessary, which is only possible if you have an entity manager to be able to persist state.

For testing with those two strategies also use addEnvironmentEntry() above.

Grega Bremec
  • 304
  • 1
  • 6
  • Mind you, as @kris-verlaenen implied above, this will only work well for synchronous processes. Do not use this with human or manual tasks. – Grega Bremec Nov 13 '15 at 07:22