[jboss-user] [jBPM] - How to configure jbpm5 to store and retrieve Knowledge Sessions from the database

Michele Mauro do-not-reply at jboss.com
Thu Feb 17 04:43:43 EST 2011


Michele Mauro [http://community.jboss.org/people/MicheleMauro] created the discussion

"How to configure jbpm5 to store and retrieve Knowledge Sessions from the database"

To view the discussion, visit: http://community.jboss.org/message/587992#587992

--------------------------------------------------------------
I'm trying to setup a web application to work with jbpm5 processes, but I'm stuck at the jbpm5 configuration. I use spring, and I can write up (messing a bit with the various examples) a test case that can create and launch a process, with a configuration along these lines in the applicationContext.xml:

<drools:ksession id="jpaSingleSessionCommandService" type="stateful" kbase="knowledgeBase">
     <drools:configuration>
            <drools:work-item-handlers>
                <drools:work-item-handler name="Human Task" ref="humanTaskHandler" />
            </drools:work-item-handlers>
           <drools:jpa-persistence load="1">
                <drools:transaction-manager ref="transactionManager" />
                <drools:entity-manager-factory ref="entityManagerFactory" />
            </drools:jpa-persistence>
    </drools:configuration>
</drools:ksession>

However, this setup creates a new ksession each time the application is loaded. In my case, I need to load a specific ksession by id, work with the process instance contained in it, inspect it for current status and results, and then persist it back.

I've tried setting up something more basic in Spring, that is building only the KnowledgeBase and then getting the session with:

StatefulKnowledgeSession ks = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);

but I keep getting strange NPEs and errors. In particular, I found that, while the documentation states (jBPM 5.0.0 manual, chapter 8) that you should build the environment to pass the JPAKnowledgeService in this way:

Environment env = KnowledgeBaseFactory.newEnvironment();
env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
env.set( EnvironmentName.TRANSACTION_MANAGER,
         TransactionManagerServices.getTransactionManager() );

the SingleSessionCommandService, that is the final implementation of the KnowledgeSession that gets called, wants a different environment:

 https://github.com/droolsjbpm/droolsjbpm/blob/master/drools-persistence-jpa/src/main/java/org/drools/persistence/SingleSessionCommandService.java https://github.com/droolsjbpm/droolsjbpm/blob/master/drools-persistence-jpa/src/main/java/org/drools/persistence/SingleSessionCommandService.java

line 56:
if ( env.get( EnvironmentName.ENTITY_MANAGER_FACTORY ) == null &&
env.get( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER ) == null  ) {
throw new IllegalArgumentException( "Environment must have an EntityManagerFactory " +
"or a PersistenceContextManager instance" );

Now I'm completely confused. How does this work?

Michele
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/587992#587992]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110217/944b1b28/attachment.html 


More information about the jboss-user mailing list