jBPM Persistence: Unable to build EntityManagerFactory

给你一囗甜甜゛ 提交于 2019-12-06 07:25:33

问题


I am trying to make my jBPM Project persistent. Therefore I used the this tutorial. At first I imported all the additional jars needed (according to the website). I also added mysql-connector-java-5.1.20-bin.jar because I want to use mysql as persistent storage.

After that I added the "stateful" code to my project:

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);
}

Then I added to resources/META-INF the file jBPM.properties:

persistence.datasource.name=jdbc/jbpm-ds

persistence.datasource.user=test

persistence.datasource.password=test

persistence.datasource.url=jdbc:mysql://localhost:3306/helpme

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

persistence.enabled=true

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

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

If I now run the project there is always the following exception (on ksession = JBPMHelper.newStatefulKnowledgeSession(kbase);):

javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory

Caused by: org.hibernate.HibernateException: Could not find datasource

Caused by: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context


回答1:


I found a solution for my Problem. Normally the JBPMHelper loads the jBPM directly from the jar:

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

I replaced the loading Mechanism and now it is loading the jBPM.properties correctly:

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

(My answer adapted from BartoszKP - thanks)



来源:https://stackoverflow.com/questions/10489713/jbpm-persistence-unable-to-build-entitymanagerfactory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!