5 Replies Latest reply: Dec 27, 2012 11:03 AM by Laura delli Paoli RSS

    Persistence.createEntityManagerFactory not working in JBoss AS 7.0.2

    renez Newbie

      Hi @ll,

       

      I created a Webservice which should start a process. I want this process to be persisted in my database. I had a look a this example (https://community.jboss.org/people/bpmn2user/blog/2011/03/25/jbpm5--persistence-hello-process-example) and configured my project like this:

       

      Webservice.class

       

      package com.example.webservices;
      
      
      import java.io.Serializable;
      import java.net.URL;
      import java.util.HashMap;
      import java.util.Map;
      import java.util.Properties;
      
      
      import javax.jws.WebService;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceUnit;
      import javax.transaction.TransactionManager;
      
      
      import org.drools.KnowledgeBase;
      import org.drools.KnowledgeBaseFactory;
      import org.drools.agent.KnowledgeAgent;
      import org.drools.agent.KnowledgeAgentFactory;
      import org.drools.base.MapGlobalResolver;
      import org.drools.io.ResourceFactory;
      import org.drools.logger.KnowledgeRuntimeLogger;
      import org.drools.logger.KnowledgeRuntimeLoggerFactory;
      import org.drools.persistence.jpa.JPAKnowledgeService;
      import org.drools.runtime.Environment;
      import org.drools.runtime.EnvironmentName;
      import org.drools.runtime.KnowledgeSessionConfiguration;
      import org.drools.runtime.StatefulKnowledgeSession;
      import org.jbpm.process.workitem.wsht.WSHumanTaskHandler;
      import org.opentrans.xmlschema._2.INVOICE;
      
      
      import bitronix.tm.TransactionManagerServices;
      import com.example.bpm.workItemHandler.BelegdatenbankWorkItemHandler;
      import com.example.bpm.workItemHandler.LeistungServiceWorkItemHandler;
      import com.example.bpm.workItemHandler.RechnungsExtractorWorkItemHandler;
      import com.example.bpm.workItemHandler.SiebelServiceWorkItemHandler;
      import com.example.bpm.workItemHandler.VertragServiceWorkItemHandler;
      import com.example.webservices.glasbruch.Glasbruch;
      import com.example.webservices.glasbruch.SubmitInvoiceFault;
      
      
      @WebService(serviceName = "glasbruchService", endpointInterface = "com.example.webservices.glasbruch.Glasbruch", targetNamespace = "http://example.com/GlasbruchService/")
      public class GlasbruchWS implements Glasbruch {
      
      
                //@PersistenceUnit(unitName="org.jbpm.persistence.jpa") 
                //EntityManagerFactory emf;
      
                private final String CS_URL = "http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/com.example.glasbruch/LATEST/ChangeSet.xml";
                private final String PROC_NAME = "com.example.Glasbruch";
      
      
                public boolean submitInvoice(org.opentrans.xmlschema._2.INVOICE invoice)
                                    throws SubmitInvoiceFault {
      
      
                          return false;
      
      
                }
      
      
                public boolean submitInvoiceRepo(INVOICE invoice) throws SubmitInvoiceFault {
                          try {
                                    URL url = new URL(CS_URL);
      
      
                                    // KBase initialisieren
                                    KnowledgeAgent kagent = KnowledgeAgentFactory
                                                        .newKnowledgeAgent("GlasbruchAgent");
                                    kagent.applyChangeSet(ResourceFactory.newUrlResource(url));
                                    KnowledgeBase kbase = kagent.getKnowledgeBase();
      
      
                                    // Prozess-Parameter initialisieren
                                    Map<String, Object> params = new HashMap<String, Object>();
                                    params.put("rechnung", invoice);
      
      
                                    // Session öffnen
                                    StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
      
                                    KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
                                                        .newFileLogger(ksession, "test");
      
      
                                    // WorkitemHandler registrieren
      
      
                                    // HT-Service starten
                                    ksession.getWorkItemManager().registerWorkItemHandler("Human Task",
                                                        new WSHumanTaskHandler());
      
      
                                    ksession.getWorkItemManager().registerWorkItemHandler(
                                                        "Belegdatenbank", new BelegdatenbankWorkItemHandler());
                                    ksession.getWorkItemManager().registerWorkItemHandler(
                                                        "RechnungsExtractor",
                                                        new RechnungsExtractorWorkItemHandler());
                                    ksession.getWorkItemManager().registerWorkItemHandler(
                                                        "SiebelService",
                                                        new SiebelServiceWorkItemHandler());
                                    ksession.getWorkItemManager().registerWorkItemHandler(
                                                        "VertragService",
                                                        new VertragServiceWorkItemHandler());
                                    ksession.getWorkItemManager().registerWorkItemHandler(
                                                        "LeistungService",
                                                        new LeistungServiceWorkItemHandler());
      
                                    // Prozess starten
                                    ksession.startProcess(PROC_NAME, params);
      
      
                                    logger.close();
      
      
                                    return true;
                          }
      
      
                          catch (Throwable t) {
      
                                    t.printStackTrace();
                                    return false;
      
      
                          }
                }
      
                private StatefulKnowledgeSession createKnowledgeSession(KnowledgeBase kbase) {
                          EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
                          Environment env = KnowledgeBaseFactory.newEnvironment();
                          env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );
                          try {
                                    TransactionManager jbossTXM = (TransactionManager) new InitialContext().lookup("java:jboss/TransactionManager");
                                    env.set( EnvironmentName.TRANSACTION_MANAGER, jbossTXM);
                          } catch (NamingException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                          }
                          //env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
      
                          env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );
      
                          Properties properties = new Properties();
                          properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");
                          properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");
                          KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);
      
                          return JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);
      
                }
      
      
      }
      
      

       

      Maven pom

       

      <?xml version="1.0"?>
      <project
                xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
                xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <modelVersion>4.0.0</modelVersion>
                <parent>
                          <artifactId>glasbruch</artifactId>
                          <groupId>com.example</groupId>
                          <version>0.0.1-SNAPSHOT</version>
                </parent>
                <artifactId>glasbruch-webservice</artifactId>
                <packaging>war</packaging>
                <name>glasbruch-webservice Maven Webapp</name>
                <url>http://maven.apache.org</url>
                <dependencies>
                          <dependency>
                                    <groupId>com.example</groupId>
                                    <artifactId>glasbruch-lib-opentrans</artifactId>
                                    <version>1.0.0.Final</version>
                                    <type>jar</type>
                                    <exclusions>
                                              <exclusion>
                                                        <artifactId>hibernate-entitymanager</artifactId>
                                                        <groupId>org.hibernate</groupId>
                                              </exclusion>
                                              <exclusion>
                                                        <artifactId>persistence-api</artifactId>
                                                        <groupId>javax.persistence</groupId>
                                              </exclusion>
                                              <exclusion>
                                                        <artifactId>dom4j</artifactId>
                                                        <groupId>dom4j</groupId>
                                              </exclusion>
                                    </exclusions>
                          </dependency>
                          <dependency>
                                    <artifactId>hibernate-core</artifactId>
                                    <groupId>org.hibernate</groupId>
                                    <version>4.0.0.CR2</version>
                                    <scope>provided</scope>
                                    <exclusions>
                                              <exclusion>
                                                        <artifactId>dom4j</artifactId>
                                                        <groupId>dom4j</groupId>
                                              </exclusion>
                                    </exclusions>
                          </dependency>
                          <dependency>
                                    <artifactId>hibernate-entitymanager</artifactId>
                                    <groupId>org.hibernate</groupId>
                                    <version>4.0.0.CR2</version>
                                    <scope>provided</scope>
                                    <exclusions>
                                              <exclusion>
                                                        <artifactId>dom4j</artifactId>
                                                        <groupId>dom4j</groupId>
                                              </exclusion>
                                    </exclusions>
                          </dependency>
                          <dependency>
                                    <groupId>com.example</groupId>
                                    <artifactId>glasbruch-workitems</artifactId>
                                    <version>0.0.1-SNAPSHOT</version>
                                    <type>jar</type>
                                    <exclusions>
                                              <exclusion>
                                                        <artifactId>persistence-api</artifactId>
                                                        <groupId>javax.persistence</groupId>
                                              </exclusion>
                                              <exclusion>
                                                        <artifactId>dom4j</artifactId>
                                                        <groupId>dom4j</groupId>
                                              </exclusion>
                                    </exclusions>
                          </dependency>
                          <dependency>
                                    <groupId>org.codehaus.btm</groupId>
                                    <artifactId>btm</artifactId>
                                    <version>1.3.3</version>
                          </dependency>
                          <dependency>
                                    <groupId>org.jbpm</groupId>
                                    <artifactId>jbpm-bpmn2</artifactId>
                          </dependency>
                          <dependency>
                                    <groupId>org.drools</groupId>
                                    <artifactId>drools-persistence-jpa</artifactId>
                                    <exclusions>
                                              <exclusion>
                                                        <artifactId>persistence-api</artifactId>
                                                        <groupId>javax.persistence</groupId>
                                              </exclusion>
                                              <exclusion>
                                                        <artifactId>dom4j</artifactId>
                                                        <groupId>dom4j</groupId>
                                              </exclusion>
                                    </exclusions>
                          </dependency>
                </dependencies>
                <build>
                          <finalName>glasbruch-webservice</finalName>
                          <plugins>
                                    <plugin>
                                              <groupId>org.apache.maven.plugins</groupId>
                                              <artifactId>maven-war-plugin</artifactId>
                                              <configuration>
                                                        <archive>
                                                                  <manifestEntries>
                                                                            <Dependencies>org.slf4j org.dom4j</Dependencies>
                                                                  </manifestEntries>
                                                        </archive>
                                              </configuration>
                                    </plugin>
                          </plugins>
                </build>
      </project>
      
      

       

      persistence.xml

       

      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <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"
                          transaction-type="JTA">
                          <!-- <provider>org.hibernate.ejb.HibernatePersistence</provider> -->
                          <jta-data-source>java:jboss/datasources/jbpmDS</jta-data-source>
                          <class>org.drools.persistence.info.SessionInfo</class>
                          <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>
                          <class>org.jbpm.persistence.processinstance.ProcessInstanceEventInfo</class>
                          <class>org.drools.persistence.info.WorkItemInfo</class>
                          <class>org.jbpm.process.audit.ProcessInstanceLog</class>
                          <class>org.jbpm.process.audit.NodeInstanceLog</class>
                          <class>org.jbpm.process.audit.VariableInstanceLog</class>
      
      
                          <class>org.jbpm.task.Task</class>
                          <class>org.jbpm.task.Comment</class>
                          <class>org.jbpm.task.Attachment</class>
                          <class>org.jbpm.task.I18NText</class>
                          <class>org.jbpm.task.SubTasksStrategy</class>
                          <class>org.jbpm.task.Deadline</class>
                          <class>org.jbpm.task.Escalation</class>
                          <class>org.jbpm.task.Reassignment</class>
                          <class>org.jbpm.task.Notification</class>
                          <class>org.jbpm.task.BooleanExpression</class>
                          <class>org.jbpm.task.User</class>
                          <class>org.jbpm.task.PeopleAssignments</class>
                          <properties>
                                    <!-- H2 dialect -->
                                    <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
                                    <!-- mysql dialect -->
                                    <!-- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/> -->
                                    <property name="hibernate.connection.autocommit" value="false" />
                                    <property name="hibernate.max_fetch_depth" value="3" />
                                    <property name="hibernate.hbm2ddl.auto" value="create" />
                                    <property name="hibernate.show_sql" value="true" />
                          </properties>
                </persistence-unit>
      
      
      </persistence>
      
      

       

      Project structure:

       

      my-war
      -META-INF
      -- MANIFEST.MF
      -WEB-INF
      -- classes
      ---META-INF
      ----orm.xml
      ----persistence.xml
      ---com
      --- ws classes
      

       

      When I call the service I always get

       

        15:54:09,534 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.jbpm.persistence.jpa
        15:54:09,534 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at com.example.webservices.GlasbruchWS.createKnowledgeSession(GlasbruchWS.java:119)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at com.example.webservices.GlasbruchWS.submitInvoiceRepo(GlasbruchWS.java:76)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at java.lang.reflect.Method.invoke(Method.java:601)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111)
        15:54:09,535 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:169)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:117)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
        15:54:09,536 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:118)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:208)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:162)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
        15:54:09,537 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:107)
        15:54:09,538 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
        15:54:09,538 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)
        15:54:09,617 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:138)
        15:54:09,617 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        15:54:09,617 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
        15:54:09,617 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
        15:54:09,618 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)
        15:54:09,618 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
        15:54:09,618 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
        15:54:09,618 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
        15:54:09,618 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:161)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        15:54:09,619 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        15:54:09,620 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
        15:54:09,620 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
        15:54:09,620 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)
        15:54:09,620 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)
        15:54:09,620 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)           at java.lang.Thread.run(Thread.java:722)
      
      

       

      In my code this is position

       

        EntityManagerFactory emf = Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );
      

       

      Any suggestion are very welcome!

       

      René