jBPM持久性:无法构建EntityManagerFactory

时间:2012-05-07 21:55:07

标签: hibernate jbpm

我正在努力使我的jBPM项目持久化。因此我使用了这个tutorial。 起初我导入了所需的所有额外的罐子(根据网站)。 我还添加了mysql-connector-java-5.1.20-bin.jar,因为我想使用mysql作为持久存储。

之后我将“有状态”代码添加到我的项目中:

KnowledgeBase kbase = readKnowledgeBase(name);
StatefulKnowledgeSession ksession = null;
JBPMHelper.startH2Server();
JBPMHelper.setupDataSource();
if(ProcessManager.sessionId == -1){
    ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);
    ProcessManager.sessionId = ksession.getId();
}
else {
ksession = JBPMHelper.loadStatefulKnowledgeSession(
    kbase,
    ProcessManager.sessionId);
}

然后我添加了resources/META-INF文件jBPM.properties

  

persistence.datasource.name = JDBC / jbpm的-DS

     

persistence.datasource.user =测试

     

persistence.datasource.password =测试

     

persistence.datasource.url = JDBC:MySQL的://本地主机:3306 / helpme

     

persistence.datasource.driverClassName = com.mysql.jdbc.Driver

     

persistence.enabled =真

     

persistence.persistenceunit.name = org.jbpm.persistence.jpa

     

persistence.persistenceunit.dialect = org.hibernate.dialect.MySQLDialect

如果我现在运行该项目,则始终存在以下异常(在ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);上):

  

javax.persistence.PersistenceException:[PersistenceUnit:org.jbpm.persistence.jpa]无法构建EntityManagerFactory

     

引起:org.hibernate.HibernateException:找不到数据源

     

引起:javax.naming.NameNotFoundException:名称jdbc未绑定在此Context中

1 个答案:

答案 0 :(得分:1)

我找到了解决问题的方法。通常,JBPMHelper直接从jar加载jBPM:

public static Properties getProperties() {
    Properties properties = new Properties();
    try {
        properties
            .load(JBPMHelper.class.getResourceAsStream("/jBPM.properties"));
    } catch (Throwable t) {
    // do nothing, use defaults
    }

    return properties;
}

我替换了加载机制,现在正在正确加载jBPM.properties

public static Properties getProperties() {
    Properties properties = new Properties();
    try {
        InputStream input
            = new FileInputStream("./resources/META-INF/jBPM.properties");
        properties.load(input);
        System.out.println("RPOP"+properties.toString());
    } catch (Throwable t) {
    // do nothing, use defaults
    }

    return properties;
}

(我的回答改编自BartoszKP - 谢谢)