0
votes

I am trying to store JBPM process data with PostgreSQL (using standalone Java application to start processes). JBPM - 5.1 (on JBoss 5.1). Postgresql - 9.1. JDBC Driver (in the app's classpath) - postgresql-9.1-901.jdbc4.

My persistence.xml (basing on JBPM Users Guide, Chapter 7.1.3) is:

<persistence version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
    xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="org.jbpm.persistence.jpa">
         <provider>org.hibernate.ejb.HibernatePersistence</provider>
         <jta-data-source>jdbc/JbpmDS</jta-data-source>
         <class>org.drools.persistence.info.SessionInfo</class>
         <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
         <class>org.drools.persistence.info.WorkItemInfo</class>
         <properties>
           <property name="hibernate.max_fetch_depth" value="3"/>
           <property name="hibernate.hbm2ddl.auto" value="update"/>
           <property name="hibernate.show_sql" value="true"/>
           <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>    
           <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
           <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /></properties></persistence-unit>
    </persistence>

And app code :

    PoolingDataSource ds = new PoolingDataSource();         
                ds.setDatabaseName("jbpm");
                ds.setUser("jbpmmanager");
                ds.setPassword("jbpm");     
                ds.setDataSourceName("jdbc/JbpmDS");
                ds.setServerName("localhost");
                ds.setPortNumber(5432);
                ds.setMaxConnections(3);            
                ds.initialize();            

                EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa"); 
.... //other code there
....

When I run it, the last line gives an exception:

2011-11-18 13:15:02 org.hibernate.util.NamingHelper getInitialContext
INFO: JNDI InitialContext properties:{}
2011-11-18 13:15:02 org.hibernate.connection.DatasourceConnectionProvider configure
SEVERE: Could not find datasource: jdbc/JbpmDS
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at com.sample.ProcessTester.main(ProcessTester.java:64)
javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
    at com.sample.ProcessTester.main(ProcessTester.java:64)
Caused by: org.hibernate.HibernateException: Could not find datasource
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:79)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:137)
    at org.hibernate.ejb.InjectionSettingsFactory.createConnectionProvider(InjectionSettingsFactory.java:29)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:89)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2101)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1325)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    ... 3 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
    at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:75)
    ... 10 more

Probably I need to do or configure something else... but I am stuck :(

2
How are you running your application? That JNDI error suggests you're not running it within a framework that provides a JNDI environment, which most application servers will do, although some webservers like Tomcat won't (without adding some additional configuration). - araqnid
It is an independent Java class with main method (well, I am new to jBPM, so now I am just testing). According to jBPM guide and jUnit tests available in jBPM source distribution, it should be enough (or I've missed something, which is quite probable :( ). I've tried also adding jndi.properies (I have deployed a data source on my running JBoss), but it doesn't wor either. - Ania
Ok. I've found the solution myself, but I cannot post the answer yet. I'll post it when I can. Maybe someone will be able to use it:) - Ania
Hmm, Hibernate is looking for a datasource via JNDI, which seems to be the cause, I guess you need to tweak the configuration so that it uses its own default pooling connection provider and the JDBC URL instead. - araqnid
@Ania What did you do to solve it? - Shyam

2 Answers

1
votes

If you are trying to deploy your application inside JBoss you should create the datasource inside the container instead of creating it from the source code as in the Unit tests that runs outside any container. Cheers

1
votes

If the jndi.properties doesn't work (jvm can't find it) simply set that property in the JVM -Djava.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory

See http://docs.codehaus.org/display/BTM/Jndi2x.