2011-11-18 65 views
0

我試圖用PostgreSQL存儲JBPM過程數據(使用獨立的Java應用程序來啓動進程)。 JBPM - 5.1(在JBoss 5.1上)。 Postgresql - 9.1。 JDBC驅動程序(在應用程序的類路徑中) - postgresql-9.1-901.jdbc4。JBPM - 存儲過程數據(PostgreSQL)

我的persistence.xml(立足於JBPM用戶指南,第7.1.3)是:

<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> 

和App代碼:

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 
.... 

當我運行它,最後一行給出了一個例外:

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 

也許我需要做什麼或配置別的東西......但我堅持:(

+0

你是如何運行你的應用程序?這個JNDI錯誤表明你沒有在提供JNDI環境的框架中運行它,儘管像Tomcat這樣的一些web服務器不會(不添加一些額外的配置),大多數應用程序服務器都會這樣做。 – araqnid

+0

它是一個獨立的Java類與主要方法(嗯,我是jBPM的新手,所以現在我只是測試)。根據jBPM源代碼分發中提供的jBPM指南和jUnit測試,它應該足夠了(或者我已經錯過了一些東西,這很可能:()。我也嘗試添加jndi.properies(我已經部署了一個數據源 – Ania

+0

好的,我自己找到了解決方案,但是我現在還不能發佈答案,我會盡快發佈,也許有人可以使用它: ) – Ania

回答

1

如果您試圖在JBoss中部署您的應用程序,您應該在容器內創建數據源,而不是像源代碼運行在任何容器之外的單元測試那樣從源代碼創建它。 乾杯