Persistence Issues for Process Persistence
mdegan Sep 27, 2013 3:20 AMHi,
I have started implementation of JBPM as our workflow solution. I am using tomcat as application server and jBPM 5.4 as the version. I am on struts so a lot of Spring examples available are not helping. Everything was working fine till I implemented Persistence for process info. I followed the instructions on user guide and created persistence.xml. Here is what I have on my persistence.xml:
<persistence-unit name="org.jbpm.runtime" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:comp/env/jdbc/jbpm-ds</jta-data-source>
<mapping-file>META-INF/JBPMorm.xml</mapping-file>
<mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file>
<class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
<class>org.jbpm.process.audit.ProcessInstanceLog</class>
<class>org.jbpm.process.audit.NodeInstanceLog</class>
<class>org.jbpm.process.audit.VariableInstanceLog</class>
<properties>
<property name="hibernate.max_fetch_depth" value="3" />
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
I have created a jBPM properties file where I have configured all the connection information and use that to create the poolingdatasource.
I am creating a pooling data source from my servlet listener class that initiates during server startup. I am doing that as follows:
Properties properties = getProperties();
// create data source
PoolingDataSource pds = new PoolingDataSource();
pds.setUniqueName(properties.getProperty("persistence.datasource.name", "jdbc/jbpm-ds"));
pds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
pds.setMaxPoolSize(5);
pds.setAllowLocalTransactions(true);
pds.getDriverProperties().put("user", properties.getProperty("persistence.datasource.user", "user"));
pds.getDriverProperties().put("password", properties.getProperty("persistence.datasource.password", "password"));
pds.getDriverProperties().put("url", properties.getProperty("persistence.datasource.url", "jdbc:mysql://localhost:3306/jbpm"));
pds.getDriverProperties().put("driverClassName", properties.getProperty("persistence.datasource.driverClassName", "com.mysql.jdbc.Driver"));
pds.init();
With this, I update the context.xml inside META-INF of my project to tell the server about the data source as follows:
<Context>
<Resource name="jdbc/jbpm-ds"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="Treefrog"
driverClassName="com.mysql.jdbc.Driver"
className="bitronix.tm.resource.jdbc.lrc.LrcXADataSource"
url="jdbc:mysql://localhost:3306/jbpm5"
uniqueName="jdbc/jbpm-ds" />
<Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory" />
</Context>
I have also updated my web.xml as follows:
<resource-env-ref>
<resource-env-ref-name>jdbc/jbpm-ds</resource-env-ref-name>
<resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
</resource-env-ref>
When I start the service, here is the log from tomcat that comes up:
javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.runtime] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
at xxxxxxxx.loadStatefulKnowledgeSession(JbpmResourceLoaderListener.java:204)
at xxxxxxxx.newStatefulKnowledgeSession(JbpmResourceLoaderListener.java:193)
at xxxxxxxx.contextInitialized(JbpmResourceLoaderListener.java:81)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:963)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1600)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
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:724)
Caused by: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [java:comp/env/jdbc/jbpm-ds]
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68)
at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 20 more
Caused by: javax.naming.NamingException: no resource registered with uniqueName 'jdbc/jbpm-ds', available resources: []
at bitronix.tm.resource.ResourceObjectFactory.getObjectInstance(ResourceObjectFactory.java:57)
at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
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:154)
at org.apache.naming.NamingContext.lookup(NamingContext.java:831)
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:154)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:135)
at javax.naming.InitialContext.lookup(InitialContext.java:415)
at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65)
... 35 more
I have tried a lot of options available on our community for this and also the documentation available on http://docs.codehaus.org/display/BTM/Tomcat13 and some other sites but havent been able to get it running. Please guide me if I am not setting something correctly.