3 Replies Latest reply on Aug 8, 2011 1:53 PM by Chaitanya Desai

    Instantiating workflow from EJB deployed as part of .ear : javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory

    Chaitanya Desai Newbie

      I am trying to instantiate a process instance based on a process definition for JBPM 5.1 from a EJB deployed in the JBoss application server. The EJB is part of a .ear file , using the MySQL database.

       

       

      I have defined a persistence unit in persistence.xml within the META-INF folder and also placed the corresponding JBPMorm.xml in the META-INF folder. The datasaource is deployed in the deploy folder of JBOss 5.1

       

      persistence .xml

       

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

           xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

            version="1.0">  

       

       

       

        <persistence-unit name="org.jbpm.persistence.jpa" transaction-type="JTA">

          <provider>org.hibernate.ejb.HibernatePersistence</provider>   

          <jta-data-source>java:jdbc/SecureAlljbpmDatasource</jta-data-source>          

          <mapping-file>META-INF/JBPMorm.xml</mapping-file>   

          <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

          <class>org.drools.persistence.info.SessionInfo</class>

          <class>org.drools.persistence.info.WorkItemInfo</class>

          <properties>   

            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>        

            <property name="hibernate.max_fetch_depth" value="3"/>

            <property name="hibernate.hbm2ddl.auto" value="create" />

            <property name="hibernate.show_sql" value="false" />

            <!-- <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> -->

            <property name="hibernate.transaction.manager_lookup_class"

                      value="org.hibernate.transaction.BTMTransactionManagerLookup"/>

          </properties>       

        </persistence-unit>

       

         </persistence>

       

      JBPMORM.XML

       

      <?xml version="1.0" encoding="UTF-8"?>

      <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"

                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                     xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"

                     version="1.0"> 

            <named-query name="ProcessInstancesWaitingForEvent">

                <query>

      select

          processInstanceInfo.processInstanceId

      from

          ProcessInstanceInfo processInstanceInfo

      where

          :type in elements(processInstanceInfo.eventTypes)

                </query>

            </named-query>

      </entity-mappings>

       

      Datasource:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <datasources>

                <local-tx-datasource>

          <jndi-name>jdbc/SecureAlljbpmDatasource</jndi-name>

          <connection-url>jdbc:mysql://localhost:3306/JBPM?useUnicode=true&amp;characterEncoding=UTF-8</connection-url>

          <!--<connection-url>jdbc:h2:mem:mydb</connection-url>-->

          <driver-class>com.mysql.jdbc.Driver</driver-class>

          <user-name>root</user-name>

          <password></password>

                <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>

                 <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>

        </local-tx-datasource>

       

      </datasources>

       

       

      When i deploy my .ear file

      App Server is able to recognise the datasource, persistence unit for jbpm datasource from persistence.xml and corresponding jbpmorm.xml.

       

      However I get the exception : javax.persistence.PersistenceException: [PersistenceUnit: org.jbpm.persistence.jpa] Unable to build EntityManagerFactory

       

      On looking into the details for it I understand that EntityManagerFactory needs to be loaded by the name: org.jbpm.persistence.jpa

      Something like:

       



      EntityManagerFactory emf =


          Persistence.createEntityManagerFactory( "org.jbpm.persistence.jpa" );

       



      Environment env = KnowledgeBaseFactory.newEnvironment();

       



      env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );


      env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());

       

       

      However I am not sure how do i define EntityManagerFactory by that name such that it gets loaded by that name during deployment rather than during run time. Can anyone please suggest me the appropriate solution for the above problem? Thanks.