2012-12-17 13 views
5

Ho problemi con l'utilizzo di Persistenza sul mio progetto jBPM.Configurazione persistenza e orm con JPA 2

La mia configurazione è jBPM 5.4 + Hibernate + JPA 2, e attualmente sto configurando il flusso di processo per connettersi a un DB con persistenza, tramite persistence.xml. Sto solo cercando di collegare la sorgente dati predefiniti (nel server H2) con la mia persistence.xml personalizzato, ma continuo a ricevere lo stesso errore più e più volte:

Unknown entity: org.jbpm.persistence.processinstance.ProcessInstanceInfo 

Ho aggiunto manualmente alla mia src/META-INF cartella il JBPMorm-JPA2.xml il seguente contenuto, ma l'errore persiste ancora. Qualcuno può aiutarmi?

JBPMorm-JPA2.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_2_0.xsd" 
       version="2.0"> 
     <named-query name="ProcessInstancesWaitingForEvent"> 
      <query> 
select 
    processInstanceInfo.processInstanceId 
from 
    ProcessInstanceInfo processInstanceInfo join processInstanceInfo.eventTypes eventTypes 
where 
    eventTypes = :type 
      </query> 
     </named-query> 

     <!-- ProcessInstanceInfo mapping (needed for JPA 2) --> 

     <entity class="org.jbpm.persistence.processinstance.ProcessInstanceInfo" 
       metadata-complete="true"> 
     <pre-update method-name="update" /> 
     <attributes> 
      <id name="processInstanceId"> 
       <column name="InstanceId" /> 
       <generated-value strategy="AUTO"/> 
      </id> 
      <basic name="processId" access="FIELD" /> 
      <basic name="startDate" access="FIELD" > 
       <temporal>DATE</temporal> 
      </basic> 
      <basic name="lastReadDate" access="FIELD" > 
       <temporal>DATE</temporal> 
      </basic> 
      <basic name="lastModificationDate" access="FIELD" > 
       <temporal>DATE</temporal> 
      </basic> 
      <basic name="state" access="FIELD" /> 
      <basic name="processInstanceByteArray" access="FIELD" > 
       <lob/> 
      </basic> 
      <version name="version" access="FIELD" > 
       <column name="OPTLOCK" /> 
      </version> 
      <element-collection name="eventTypes" target-class="java.lang.String" access="FIELD" > 
       <collection-table name="EventTypes"> 
        <join-column name="InstanceId"/> 
       </collection-table> 
      </element-collection> 
      <transient name="processInstance" /> 
      <transient name="env" /> 
     </attributes> 
     </entity> 

</entity-mappings> 

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="IALPR" transaction-type="JTA"> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <jta-data-source>jdbc/jbpm-ds</jta-data-source> 
    <class>org.drools.persistence.info.SessionInfo</class> 
    <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class> 
    <class>org.drools.persistence.info.WorkItemInfo</class> 

    <properties> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/> 
     <property name="hibernate.max_fetch_depth" value="3"/> 
     <property name="hibernate.hbm2ddl.auto" value="update"/> 
     <property name="hibernate.show_sql" value="true"/> 
     <property name="hibernate.transaction.manager_lookup_class" 
       value="org.hibernate.transaction.BTMTransactionManagerLookup"/> 

    </properties> 

    </persistence-unit> 

</persistence> 

UPDATE:

Per risolvere questo problema, creare un ProcessInstanceInfo.hbm.xml nel META -INF cartella, con il seguente contenuto:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > <hibernate-mapping package="org.jbpm.persistence.processinstance"> 

    <!-- access="field" for fields that have no setter methods --> 
    <class name="ProcessInstanceInfo" table="ProcessInstanceInfo"> 

     <id name="processInstanceId" type="long" column="InstanceId"> 
      <generator class="native" /> 
     </id> 

     <version name="version" type="integer" unsaved-value="null" access="field"> 
      <column name="OPTLOCK" not-null="false" /> 
     </version> 

     <property name="processId" access="field" /> 
     <property name="startDate" type="timestamp" access="field" /> 
     <property name="lastReadDate" type="timestamp" access="field" /> 
     <property name="lastModificationDate" type="timestamp" access="field" /> 
     <property name="state" type="integer" not-null="true" access="field" /> 

     <property name="processInstanceByteArray" type="org.hibernate.type.PrimitiveByteArrayBlobType" 
      column="processInstanceByteArray" access="field" length="2147483647" /> 

     <set name="eventTypes" table="EventTypes" access="field" > 
      <key column="InstanceId"/> 
      <element column="element" type="string"/> 
     </set> 

     <!-- NOT mapping [processInstance] field because field is transient -->  
     <!-- NOT mapping [env] field because field is transient -->  

    </class> 

</hibernate-mapping> 

Se qualcuno conosce un buon tutorial sulla configurazione di persistenza per jBPM5, si prega di condividere ... questo è folle!

risposta

7

Ok, quindi ecco qui un piccolo tutorial per configurare la persistenza in JBPM, utilizzando un database MySQL e JBoss AS:

1) Creare una cartella META-INF nella cartella di/java src/main

2) Creare persistence.xml

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="1.0" 
      xmlns="http://java.sun.com/xml/ns/persistence" 
      xmlns:orm="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 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"> 

    <persistence-unit name="your_unit_name" transaction-type="JTA"> 
     <provider>org.hibernate.ejb.HibernatePersistence</provider> 
     <jta-data-source>java:/your_data_source_name</jta-data-source>   
     <mapping-file>META-INF/JBPMorm.xml</mapping-file> 
     <mapping-file>META-INF/ProcessInstanceInfo.hbm.xml</mapping-file> 

     <!-- The tables that will be created in your specified sql schema --> 
     <class>org.drools.persistence.info.SessionInfo</class> 
     <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class> 
     <class>org.drools.persistence.info.WorkItemInfo</class> 

     <properties> 

     <property name="hibernate.default_schema" value="your_schema_name" /> 

      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" /> 
      <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="false" /> 
      <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" /> 

     </properties>   
    </persistence-unit> 





</persistence> 

3) Creare orm.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> 

4) Creare ProcessInstanceInfo.hbm.xml

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" > 
<hibernate-mapping package="org.jbpm.persistence.processinstance"> 

    <!-- access="field" for fields that have no setter methods --> 
    <class name="ProcessInstanceInfo" table="ProcessInstanceInfo"> 

     <id name="processInstanceId" type="long" column="InstanceId"> 
      <generator class="native" /> 
     </id> 

     <version name="version" type="integer" unsaved-value="null" access="field"> 
      <column name="OPTLOCK" not-null="false" /> 
     </version> 

     <property name="processId" access="field" /> 
     <property name="startDate" type="timestamp" access="field" /> 
     <property name="lastReadDate" type="timestamp" access="field" /> 
     <property name="lastModificationDate" type="timestamp" access="field" /> 
     <property name="state" type="integer" not-null="true" access="field" /> 

     <property name="processInstanceByteArray" type="org.hibernate.type.PrimitiveByteArrayBlobType" 
      column="processInstanceByteArray" access="field" length="2147483647" /> 

     <set name="eventTypes" table="EventTypes" access="field" > 
      <key column="InstanceId"/> 
      <element column="element" type="string"/> 
     </set> 

     <!-- NOT mapping [processInstance] field because field is transient -->  
     <!-- NOT mapping [env] field because field is transient -->  

    </class> 

</hibernate-mapping> 

5) Ora è necessario definire l'origine dati. Io uso JBoss5 e questa versione di JBoss leggerà qualsiasi file con il modello * -ds.xml come la definizione dell'origine dati. Devi inserire questo file nella tua cartella di distribuzione (e potresti notare che c'è già un file di origine dati, ma non ci saranno conflitti). Se stai usando JBoss7, c'è un modo diverso per definire il DS - suppongo che ciò potrebbe essere utile https://community.jboss.org/wiki/DataSourceConfigurationInAS7.

Ad ogni modo, ecco cosa il vostro yourDS-ds.xml dovrebbe essere simile:

<datasources> 
    <local-tx-datasource> 
    <jndi-name>jdbc/your_datasource_name</jndi-name> 
    <connection-url>your_db_url</connection-url> 
    <driver-class>com.mysql.jdbc.Driver</driver-class> 
    <user-name>your_user</user-name> 
    <password>your_pass</password> 
    <min-pool-size>5</min-pool-size> 
    <max-pool-size>20</max-pool-size> 
    <idle-timeout-minutes>5</idle-timeout-minutes> 
    </local-tx-datasource> 
</datasources> 

6) Le istruzioni di cui sopra sono sufficienti per almeno creare le tabelle di persistenza nel database. Quando alla fine inizi a utilizzare le attività in JBPM, potrebbe essere necessario creare un file Taskorm.xml (google, è troppo lungo). Non sono sicuro che sia necessario, ma ce l'ho comunque.

7) Infine, è sufficiente chiamare l'unità di persistenza in Java tramite EntityManagerFactory, creare il proprio ambiente e avviare una nuova sessione. I dati di persistenza dovrebbero essere automaticamente salvati nel DB.

Spero che questo sia stato utile. Saluti!

+0

Ero in vacanza, mi dispiace non aver potuto rispondere prima. Si salva il file orm.xml nella cartella META-INF sotto la cartella src/main/java –

Problemi correlati