[rules-users] Drools 6 Spring JTA Persistence

Alexander Herwix alex at herwix.com
Tue Sep 3 15:00:49 EDT 2013


Hey guys, 

I'm working on a Grails plugin for Drools/Jbpm 6 and I have trouble to get persistence working in a user friendly way. It would be awesome if someone with a better understanding of drools and especially drools spring integration could help me to figure this out :) 

I have considered multiple approaches:

- Use a spring LocalContainerEntityManagerFactoryBean with a local JpaTransactionManager to configure a KieEnvironment via Spring.

I basically got this working, but this doesn't provide real integration with Grails, as there are 2 seperate local TransactionManagers involved - limiting the ability to integrate drools in the grails app.

- Use JTA-Transactions. 

As I want the plugin to be as user friendly as possible I would like to keep using the default tomcat container for development. There is the Atomikos Plugin for Grails which configures Grails to work with JTA. This works pretty nicely and should suffice for the development environment. 

My problem is integrating the Atomikos backed JTATransactionManager with the drools 6 spring environment configuration as I have not much experience with JTA. I have looked at the Tests for Kie-Spring and looked at as much documentation as I could find, but I can't seem to figure this out. 

This is what I use to configure the environment via spring (in Grails groovy syntax)

jbpmGlobals(MapGlobalResolver)

    dacceptor(ClassObjectMarshallingStrategyAcceptor,['*.*'])

    kie.kstore(id:'kiestore')

    kie.environment(id: 'jbpmEnv'){
        kie.'entity-manager-factory'(ref:'entityManagerFactory')

        kie.globals(ref:'jbpmGlobals')

        kie.'object-marshalling-strategies'(){
            kie.'jpa-placeholder-resolver-strategy'()
            kie.'serializable-placeholder-resolver-strategy'('strategy-acceptor-ref':"dacceptor")
        }
    }
//Tried to wrap my JtaTransactionManager with KieSpringTransactionManager
jbpmTransactionManager(KieSpringTransactionManager, ref('transactionManager'))

the environment value for transactionManager cannot be set here, because the parser expects a JpaTransactionManager. I tried to add the transactionManager manually to the environment and found the KieSpringTransactionManager, which looked like it could help me somehow, but in the end, there is always the default implementation of the JtaTransactionManager used which can't find the transactionManager that I configured. 

Error:
NamingException occurred when processing request: [GET] /bpm/test/testJbpm
Cannot create resource instance. Stacktrace follows:
javax.naming.NamingException: Cannot create resource instance
	at org.apache.naming.factory.TransactionFactory.getObjectInstance(TransactionFactory.java:116)
	at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:321)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:843)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:154)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
	at javax.naming.InitialContext.lookup(InitialContext.java:411)
	at org.drools.persistence.jta.JtaTransactionManager.findUserTransaction(JtaTransactionManager.java:122)
	at org.drools.persistence.jta.JtaTransactionManager.<init>(JtaTransactionManager.java:69)
	at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:325)
	at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:114)
	at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:129)
	at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:67)
	at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:36)
	at bpm.TestController.testJbpm(TestController.groovy:119)
	at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
	at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:722)


I would be glad about any input. 

Cheers, Alex

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130903/56099162/attachment.html 


More information about the rules-users mailing list