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